1、 获取UITextField所以Cell的NSIndexPath,知道了NSIndexPath就知道了这个UITextField用来做什么:
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
//get cell
UITableViewCell *cell = [UITableViewCell ][[textField superview] superview];
NSIndexPath *indexPath = [tableView indexPathForCell:cell];
}
<span style="color:#ff0000;">注意: [[textField superview] superview] textField 是放在contentView的,contentView的superView才是cell</span>
- (void)textFieldDidEndEditing:(UITextField *)textField
{
//get cell
UITableViewCell *cell = (UITableViewCell *)[[textField superview] superview];
NSIndexPath *indexPath = [tableView indexPathForCell:cell];
}
上述两种方法都可获取cell中的textField