作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在使用一个自定义的 tablecell
,我希望在该 cell
中有两个按钮操作,一个用于 pushViewController
,一个用于 popViewControllerAnimated
如何实现?
最佳答案
在您的自定义单元格中,您必须创建两个按钮。在您的 cellForRowAtIndexPath
中写入以下代码:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CellCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"customCell"];
cell.btnPop.tag = indexPath.row;
[cell.btnPop addTarget:self action:@selector(popButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
cell.btnPush.tag = indexPath.row;
[cell.btnPush addTarget:self action:@selector(pushButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
return cell;
}
为按钮设置标签很重要,因为它们会告诉您点击了哪一行按钮。
定义你的行为:
-(void)popButtonClicked:(id)sender
{
}
-(void)pushButtonClicked:(id)sender
{
}
关于ios - 如何在 ios 中的自定义表格单元格内创建按钮操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24444245/
我是一名优秀的程序员,十分优秀!