美文网首页专注iOS开发A知识点2iOS
iOS 开发技巧 - UITableView 取消点击cell的

iOS 开发技巧 - UITableView 取消点击cell的

作者: devZhang | 来源:发表于2016-05-19 16:06 被阅读9436次

    这个分享,依然是关于 UITableView 的。 应该有遇到过,在点击cell得时候,默认会有一个选中状态的背景颜色,一般是灰色的,怎么取消呢? 分享一下

    方法一:

    Table view data source- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath方法里直接调用[tableView deselectRowAtIndexPath:indexPath animated:NO]; 就可以了。

    就是这样

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        [tableView deselectRowAtIndexPath:indexPath animated:NO];
    }
    

    OK,效果完成,之后点击cell抬起手指之后,就没有那个选中的灰色背景颜色了。

    方法二:多谢Softwaretailor 提醒,我忘了之前使用过的一个简单设置方法了

    直接在-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 方法里面加上一句:cell.selectionStyle = UITableViewCellSelectionStyleNone;也能达到效果。

    相关文章

      网友评论

      本文标题:iOS 开发技巧 - UITableView 取消点击cell的

      本文链接:https://www.haomeiwen.com/subject/lcjgrttx.html