gpt4 book ai didi

iOS:在自定义 UITableViewCell 中更改 contentView backgroundColor on touchDown

转载 作者:行者123 更新时间:2023-12-01 18:49:01 24 4
gpt4 key购买 nike

问题

我需要在自定义 UITableViewCell 中的 touchDown 事件上更改 contentView 的 backgroundColor 属性。我已经向单元格添加了一个 UIButton,但似乎无法弄清楚如何让它重新加载单元格并更改单元格的 contentView backgroundColor。

我试过的:

我将目标添加到 cellForRow:atIndexPath: 中的 UIButton,如下所示:

[cell.touchButton addTarget:self action:@selector(touchButtonAtIndexPath:) forControlEvents:UIControlEventTouchDown];

这是我应该重新加载所选单元格的方法:
-(void) touchButtonAtIndexPath:(NSIndexPath *)indexPath {

cellSelected = YES;

[self.tableView beginUpdates];
[self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
[self.tableView endUpdates];

}

当该单元重新加载时,这是应该更改 contentView 的背景颜色的代码:
if (cellSelected) {
cell.contentView.backgroundColor = [UIColor blueColor];
}

我在 touchButtonAtIndexPath: 方法中收到错误,这是错误:
-[UIButton section]: unrecognized selector sent to instance

任何人都知道如何在 touchDown 上更新自定义 UITableViewCell 的 contentView backgroundColor?谢谢!

最佳答案

使用这些委托(delegate)函数:

func tableView(tableView: UITableView, didHighlightRowAtIndexPath indexPath: NSIndexPath) {
// Do your stuff when selected
}


func tableView(tableView: UITableView, didUnhighlightRowAtIndexPath indexPath: NSIndexPath) {
// Do your stuff when unselected

}

关于iOS:在自定义 UITableViewCell 中更改 contentView backgroundColor on touchDown,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32632865/

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