zoukankan      html  css  js  c++  java
  • iOS-单选cell的实现

    一、思路

      先设置一个chooseCelltag标记(类型为NSIndexPath),然后在点击cell触发的时候,如果tag设置有值,就设置

         

     UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:tag];
    
              selectedCell.accessoryType = UITableViewCellAccessoryNone;

      然后把tag = indexPath

      然后

      

    cell.accessoryType = UITableViewCellAccessoryCheckmark;

    二、主要代码:

    1、在.m的interface中

    @interface ChooseTypeViewController ()
    
    {
    
        NSIndexPath *tag; 
    
    }
    
    @end

    2、在点击cell触发的事件中。

    -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    
    {
    
        [tableView deselectRowAtIndexPath:indexPath animated:TRUE];
    
        UITableViewCell *cell = [tableView cellForRowAtIndexPath: indexPath];
    
        if (tag) {
    
            UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:tag];
    
            selectedCell.accessoryType = UITableViewCellAccessoryNone;
    
        }
    
        tag = indexPath;
    
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    
    }
  • 相关阅读:
    GitLab-添加SSH Key亲历教程
    java-数组Array的应用总结
    Java-方法的重载和重写
    JSON-相关的工具收藏分享
    java-无重复的排列组合小技能
    Charles安装与使用
    深拷贝浅拷贝
    文件操作
    列表生成式
    非空即真,非零即真
  • 原文地址:https://www.cnblogs.com/zhanggui/p/4280854.html
Copyright © 2011-2022 走看看