ios - 如何在 ios 中的自定义表格单元格内创建按钮操作

标签 ios iphone xcode uitableview

我正在使用自定义的 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/

相关文章:

javascript - 使用 .click() 模拟文件输入点击在 iOS 中不起作用 - Cordova

ios - 在 iOS8 中创建 "continue"箭头按钮

ios - 如何在iOS和TvOS应用之间传递数据?

iphone - 启动电话应用程序以调用没有号码的电话

ios - 在框架中嵌入框架 (iOS 8+)

ios - SceneKit - 音频在我第一次播放声音时导致 cxa_throw 延迟

ios - 如何为两个不同的选择器 View 调用两个不同的数组(swift4)

iphone - Phonegap-无法从JavaScript调用本地iOS功能

iphone - 我们可以获取 iPhone 中配置的总电子邮件帐户吗?

iphone - 在 iPhone 中获取 Facebook/Twitter 好友的 Foursquare 位置。