gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:04:31 24 4
gpt4 key购买 nike

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com