【发布时间】:2015-07-28 19:52:51
【问题描述】:
我有一个有几行的UITableView,其中可能包含UITextFields。我为此UITableViewCells 创建了一个自定义类。这个自定义类有一个委托,如下所示:
@interface GKCustomCell : UITableViewCell <UITextFieldDelegate>
@property (nonatomic, strong) UITextField *textField;
@property (nonatomic, strong) id<UITextFieldDelegate> delegate;
@end
我的TableViewController符合<UITextFieldDelegate>协议,所以我可以在-tableView:cellForRowAtIndexPath:中分配自己:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
GKCustomCell *cell = (GKCustomCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
cell.delegate = self;
...
return cell;
}
cell的方法直接调用它的delegate对应的方法如下:
- (void)textFieldDidEndEditing:(UITextField *)textField
{
[self.delegate textFieldDidEndEditing:textField];
}
所以我已经知道如何正确访问在我的控制器的单元格中发生的UITextField 事件。
我的问题是,我想通过某种逻辑选择文本字段(使它们成为firstResponder)(例如,按下完成的下一个)。为此,我显然需要单元格中UITextField 的引用,它没有也不能有(因为行是动态出队的,所以我不能在我的表格视图控制器中将强引用放入单元格的内部对象)。
我怎样才能优雅地访问这些UITextFields 之一?
【问题讨论】:
标签: objective-c uitableview uitextfield