自定义的UITableViewCell项问题
-
16-09-2019 - |
题
我是新手。
我有一个自定义的UITableViewCell与3个项目:
一个UILabel 为UITextField 和一个UIButton
我的问题是,我怎么知道从哪个单元中的按钮被点击或文本字段被编辑?
有没有一种方法来跟踪他们?
感谢您的任何答复。
解决方案
我平时被配置自定义小区后,我保存的小区的NSIndexPath什么在用于状态UIControlStateApplication按钮的标题。
在您的tableView:的cellForRowAtIndexPath:方法,配置所述小区时:
[theButton setTitle:(NSString *)indexPath forState:UIControlStateApplication];
然后,在你的按钮动作:
- (IBAction) buttonWasClicked:(UIButton *) senderButton {
NSIndexPath *indexPath;
indexPath = (NSIndexPath *)[senderButton titleForState:UIControlStateApplication];
NSLog(@"Sender button was clicked in cell at NSIndexPath section: %d row: %d ", [indexPath section], [indexPath row]);
}
我不这样真的很高兴。如果有人有一个更清洁的方式做到这一点,我将非常乐意倾听一下。
其他提示
如果你只有一个部分,你可以在indexPath.row
存储在button.tag
和由该按钮触发的操作进行检索。
不隶属于 StackOverflow