所以我在 UIViewController (不是表视图控制器)中的 UITableView 的单元格中有一系列文本字段。我可以编辑文本字段,但没有调用像 - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField 这样的委托方法。
视图控制器有它的委托集:
@interface NRSignUpViewController : UIViewController<UITextFieldDelegate, UIPickerViewDelegate, UIPickerViewDataSource, UITableViewDelegate, UITableViewDataSource>
声明的字段:
@property (nonatomic, strong) UITextField *firstName;
@property (nonatomic, strong) UITextField *lastName;
@property (nonatomic, strong) UITextField *email;
并且代表在 viewDidLoad 中设置:
_firstName.delegate = self;
_lastName.delegate = self;
_email.delegate = self;
这是 cellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [table dequeueReusableCellWithIdentifier:@"Cell"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:@"Cell"];
cell.accessoryType = UITableViewCellAccessoryNone;
}
UITextField *tf = [[UITextField alloc] initWithFrame:CGRectMake(10, 10, table.frame.size.width-20, 30)];
tf.textColor = [UIColor blackColor];
tf.returnKeyType = UIReturnKeyNext;
switch (indexPath.row) {
case 0:
tf.placeholder = @"First name";
tf.autocapitalizationType = UITextAutocapitalizationTypeWords;
_firstName = tf;
break;
case 1:
tf.placeholder = @"Last name";
tf.autocapitalizationType = UITextAutocapitalizationTypeWords;
_lastName = tf;
break;
case 2:
tf.placeholder = @"Email address";
tf.autocapitalizationType = UITextAutocapitalizationTypeNone;
tf.keyboardType = UIKeyboardTypeEmailAddress;
_email = tf;
break;
default:
break;
}
[cell.contentView addSubview:tf];
return cell;
}
有什么想法可能会丢失吗?