2014-05-09 6 views
0

의 일부인 UITableViewUITableViewCellUITextField이 있습니다. TextFields이 보이고 그들을 클릭 할 수 있습니다 (키보드가 나타납니다). 그러나 textFieldShouldReturn 메서드는 작동하지 않습니다. 이 같은 위임합니다textFieldShouldReturn이 UITableViewCell의 UITextField에서 응답하지 않았습니다.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 
VVUserInformationCell *cell = [tableView dequeueReusableCellWithIdentifier:cellUserIdentifier forIndexPath:indexPath]; 

[cell setSelectionStyle:UITableViewCellSelectionStyleNone]; 
cell.userData.delegate = self; 

[cell.typeLabel setText: array[indexPath.row][0]]; 
[cell.userData setTextAlignment: NSTextAlignmentRight]; 

return cell; 

은}

-(BOOL)textfieldShouldReturn:(UITextField*)textField{ 
NSError* e = nil; 
NSLog(@"HEJ!"); 

switch (textField.tag) { 
    case 0: 
     arrayStr = [textField.text componentsSeparatedByString:@" "]; 
     self.currentAttendee.firstName = arrayStr[0]; 
     self.currentAttendee.lastName = arrayStr[1]; 
     break; 

    case 1: 
     self.currentAttendee.username = textField.text; 
     break; 

    case 2: 
     self.currentAttendee.email = textField.text; 
     break; 

    case 3: 
     arrayStr = [textField.text componentsSeparatedByString:@" "]; 
     self.currentAttendee.firstName = arrayStr[0]; 
     self.currentAttendee.lastName = arrayStr[1]; 
     break; 

    case 4: 
     self.currentAttendee.username = textField.text; 
     break; 

    case 5: 
     self.currentAttendee.email = textField.text; 
     break; 

    default: 
     break; 
} 
[textField resignFirstResponder]; 
return YES; 

[self.currentAttendee.managedObjectContext save:&e]; 
NSAssert(!e,@"Error saving to API: %@",e); 

}

나는 textfieldshould 반환의 내부 brakepoint을 만들었지 만 거기 가지 않았다.

편집 : userData는 내 TextField입니다.

+2

텍스트 필드의 위임을 설정 했습니까 ??? –

답변

0

UITextField은 어디에 있습니까?

나는 당신이 그것을 가지고 당신이 경우 cellForRowAtIndexPath:

어디서나으로 설정이 표시되지 않습니다 그것을 당신이 UITableViewController에의 위임을 설정해야합니다 셀의 속성입니다 :

cell.textField.delegate = self; 

를 이제 보기 컨트롤러는 textfieldShouldReturn:에 응답합니다.

@interface MyTableViewController : UITableViewController <UITextFieldDelegate> 

// ... 

@end 
+0

userData는이 셀의 textField입니다. – xav9211

2

귀하의 방법은 다음과 같습니다 :

- (BOOL)textfieldShouldReturn:(UITextField *)textField; 

올바른 방법은 다음과 같습니다

- (BOOL)textFieldShouldReturn:(UITextField *)textField; 

그들은에 의해 다른

또한

, 당신의 UITableViewController가 UITextFieldDelegate 프로토콜을 준수하는지 확인 도)

관련 문제