zoukankan      html  css  js  c++  java
  • TabelView的多选模式

    @interface ViewController ()<UITableViewDelegate,UITableViewDataSource>

    @property(nonatomic,strong) NSMutableArray *dataSourceArray;

    @end

    @implementation ViewController

    - (void)viewDidLoad {

        [super viewDidLoad];

        self.dataSourceArray  = [NSMutableArray arrayWithObjects:@"A", @"B", @"C", @"D", @"E", @"F", @"G", @"H", @"I", @"J", @"K", @"L", @"M", nil];

        UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];

        tableView.delegate=  self;

        tableView.dataSource = self;

        //打开编辑状态

        [tableView setEditing:YES animated:YES];

        [self.view addSubview:tableView];

    }

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

    {

        return self.dataSourceArray.count;

    }

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

    {

        static NSString *cellIdentifier = @"Cell";

        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

        if (!cell)

        {

            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];

            

        }

        cell.textLabel.text = self.dataSourceArray[indexPath.row];

        

        return cell;

    }

    //这两个参数 一个一个写就是各自的状态,两个一起写 就成了前面的有圆圈的多选状态

    - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath

    {

        return UITableViewCellEditingStyleDelete | UITableViewCellEditingStyleInsert;

    }

    //点击cell选择  往你数据源数组里面加东西

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    }

    //这个是取消点击的cell 删除你数据源的东西

    - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{

    }

    //根据上面的两个方法 删除你的cell和你的数据源的东西 记得刷新表

     实现的效果

  • 相关阅读:
    (转)学习笔记viewController(欢迎指错)
    配置Xcode版本控制SVN详细步骤内含解决Xcode/Mac OS10.8无法配置SVN的解决方法(转)
    iPhone 3G/3GS(有锁)基带与导航功能
    [转]Iphone 3G/3Gs Home键失灵的根本原因和解决方法
    NSDate的常用用法(转)
    短信操作(转)
    如何在Symbian SDK下使用GCCE4(转)
    nS60_sdk_v1_2的VC6问题(转)
    如何获取应用程序图标(转)
    如何实现圆角的UITextView iphone短信发送(非系统界面)
  • 原文地址:https://www.cnblogs.com/yuejunjie/p/5147279.html
Copyright © 2011-2022 走看看