OGeek|极客世界-中国程序员成长平台

标题: iphone - 当我们持有 UITableViewCell 时会调用哪个方法 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 11:51
标题: iphone - 当我们持有 UITableViewCell 时会调用哪个方法

当我们选择 UITableViewCell 时比 - (void)tableViewUITableView *)tableView didSelectRowAtIndexPathNSIndexPath *)indexPath 调用了。

但是如果我们持有 UITebleViewCell 会调用哪个方法。伙计们,我的问题是我创建了一个包含大单元格的表格 View ,并且在该单元格中我正在设置各种 View View 的背景颜色。

当我选择单元格时,我的单元格的背景颜色将消失。我已经通过在 didSelectRowAtIndexPath 这样的方法中再次设置 View 背景颜色解决了这个问题。

- (void)tableViewUITableView *)tableView didSelectRowAtIndexPathNSIndexPath *)indexPath
{
    UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];

    UIView *vLineview=[selectedCell viewWithTag:1];
    vLineview.backgroundColor = [UIColor colorWithRed89/255.0) green89/255.0) blue89/255.0) alpha:1];
}

这成功了,我的 View 背景颜色将显示,但是当我拿着 UITableViewCell 时,它会再次消失。

我该如何解决这个问题?我是否必须和手势识别器来检测长触摸并在其中实现我的 View 背景方法?或者还有其他可用的方法。



Best Answer-推荐答案


尝试在 cellForRowAtIndexPath 中设置单元格选择样式 none like this

[cell setSelectionStyle:UITableViewCellSelectionStyleNone];

关于iphone - 当我们持有 UITableViewCell 时会调用哪个方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17190902/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4