所以我有一個UIViewController(不表視圖控制器)內的生活一個UITableView細胞一系列的文本字段。我可以編輯文本字段,但像 - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField這樣的委託方法沒有被調用。的UITextField委託方法不叫
視圖控制器具有其委託集:
@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;
}
任何想法可能會丟失什麼?
對於斯威夫特:確保委託方法不是私有擴展;儘管 – iwasrobbed