我已经有段时间没有编码iOS了,而且我正在目睹一些新行为,并且想知道它是如何工作的。如何使用UITableViewController的新单元格重用行为初始化单元格
它曾经是cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath]
会返回一个细胞或不,但我现在看到的代码示例缺少初始化部分:
if (cell == nil) {
cell = [MyCellClass new];//and I think somehow registering the cell with the identifier
//Some code here, for example:
//[cell.button addTarget:self action:@selector(buttonPressedAction:) forControlEvents:UIControlEventTouchUpInside];
}
难道要做到这些初始化每次现在,没有检查细胞的存在?
编辑:我的使用情况的详细信息: 我的手机有一个NIB文件,我用我的ViewController
的viewDidLoad
新[[self tableView] registerNib:[UINib nibWithNibName:@"cell" bundle:nil] forCellReuseIdentifier:@"cell"]
。我的ViewController
不存在于任何Nib/StoryBoard中。
我明白了。现在,安装ControlEvent侦听器的最佳做法是什么?在每个'tableView:cellForRowAtIndexPath:',应该调用'addTarget:action:forControlEvents:'? (考虑到在我的使用情况下,它应该以编程方式完成。单元格和控制器不在同一个笔尖/故事板中) – Mabedan
要判断一行是否被轻敲(大概这就是你想要做的?), tableView:didSelectRowAtIndexPath:在你的表视图控制器中。 –
我试图检测单元格内的UIButton是否已被挖掘 – Mabedan