首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

自定义 UITableViewCell 怎么在子控件触发时得到 indexPath

2012-08-30 
自定义 UITableViewCell 怎样在子控件触发时得到 indexPath例如 每个UITableViewCell里有个UITextField,当

自定义 UITableViewCell 怎样在子控件触发时得到 indexPath
例如 每个UITableViewCell里有个UITextField,当UITextField获得焦点时不会触发tableview的didSelectRowAtIndexPath方法,就不能知道触发是哪个cell,下面方法可以获得UITextField所在行的indexPath,方法很简单,注意两种方式。

如果是将textField添加在cell.contentView上:

//获得rowNSInteger row = [[self.tableView indexPathForCell:(UITableViewCell *)[sender superview]] row];//获得sectionNSInteger section = [[self.tableView indexPathForCell:(UITableViewCell *)[sender superview]] section];//获得indexPathNSIndexPath *indexPath = [self.tableView indexPathForCell:(UITableViewCell *)[sender superview]];

热点排行