【发布时间】:2013-09-26 08:39:34
【问题描述】:
我有一个名为EditableTableViewCell 的自定义UItableViewCell 类(除其他内容外)在其contentView 中添加了一个UITextField。在Textfield 委托方法中,我试图检测它属于哪个部分。像这样:
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
UIView* contentView =[textField superview];
//traverse up in the view hierarchy until we find the cell's content view.
while (![contentView isKindOfClass:[EditableTableViewCell class]] || contentView.superview == nil) {
contentView = [contentView superview];
}
EditableTableViewCell *thiscell = (EditableTableViewCell*)contentView;
NSIndexPath *indexpath =[[self tableView]indexPathForRowAtPoint:thiscell.center];
这给了我正确的结果,我看到了类似的解决方案 here 也导航视图层次结构。我想知道这是否是唯一的解决方案,或者是否有更合适的方法不涉及循环所有可用单元格。
【问题讨论】:
标签: ios uitableview ios7