gpt4 book ai didi

iphone - 如何在 UITableView 上添加按钮而不使用自定义单元格?

转载 作者:行者123 更新时间:2023-12-03 20:22:44 27 4
gpt4 key购买 nike

如何在 UITableViewCell 上添加自定义按钮,然后在不使用 Interface Builder 和自定义单元格的情况下删除带有该按钮的单元格?

最佳答案

如果您确实想添加自定义按钮而不进行子类化,只需将按钮添加到单元格的 contentView 中即可:

[cell.contentView addSubview:customButton];

您可以设置按钮的所有特征:框架、目标、选择器等...然后广告使用上面的调用将其添加到单元格中。

UIButton *customButton = [UIButton buttonWithType:UIButtonTypeCustom];
customButton.frame=//whatever
[customButton setImage:anImage forState:UIControlStateNormal];
[customButton setImage:anotherImage forState:UIControlStateHighlighted];
[customButton addTarget:self action:@selector(delete) forControlEvents: UIControlEventTouchUpInside];
//yadda, yadda, .....

您也可以标记它

customButton.tag = 99999;

这样您以后就可以找到它:

UIButton *abutton = (UIButton*) [cell.contentView viewWithTag:99999];

您需要决定何时添加按钮,也许是在单元格选择时,也许是在编辑模式下......只需将代码放入您选择的委托(delegate)方法中即可。

关于iphone - 如何在 UITableView 上添加按钮而不使用自定义单元格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/851498/

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