gpt4 book ai didi

ios - 未调用 UITextField 委托(delegate)方法

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:08:01 26 4
gpt4 key购买 nike

所以我在 UIViewController(不是 TableView Controller )中的 UITableView 的单元格中有一系列文本字段。我可以编辑文本字段,但不会调用诸如 - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField 之类的委托(delegate)方法。

View Controller 有它的委托(delegate)集:

@interface NRSignUpViewController : UIViewController<UITextFieldDelegate, UIPickerViewDelegate, UIPickerViewDataSource, UITableViewDelegate, UITableViewDataSource>

声明的字段:

@property (nonatomic, strong) UITextField *firstName;
@property (nonatomic, strong) UITextField *lastName;
@property (nonatomic, strong) UITextField *email;

委托(delegate)在 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;
}

有什么可能遗漏的想法吗?

最佳答案

您在 viewDidLoad 中设置委托(delegate),但直到 cellForRow... 才真正创建文本字段。

关于ios - 未调用 UITextField 委托(delegate)方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19083583/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com