您的位置:首页 > 产品设计 > UI/UE

IOS开发笔记-UITableView的多选

2015-11-26 09:19 302 查看
//

//  JPViewController.m

//  MultiSelectDemo

//

//  Created by kuaitu on 15/1/9.

//  Copyright (c) 2015年JP. All rights reserved.

//

#import "JPViewController.h"

@interface JPViewController ()

@end

@implementation JPViewController

{

    int _row;

    int _rowNum;

    BOOL _selected[20];

}

- (void)viewDidLoad

{

    [super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

    

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

    

    

    tableView.delegate = self;

    tableView.dataSource = self;

    

    [self.view addSubview:tableView];

}

#pragma mark - UITableViewDatasource

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

{

    return 20;

}

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

{

    static NSString *cellIdentifier = @"cell";

    

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    

    if (cell == nil)

    {

        cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:cellIdentifier];

    }

    

    cell.tintColor = [UIColorredColor];

    

    if (_selected[indexPath.row]) {

        cell.accessoryType =UITableViewCellAccessoryCheckmark;

        

    }

    else

    {

        cell.accessoryType =UITableViewCellAccessoryNone;

        

    }

    cell.textLabel.text =@"111";

    return cell;

}

#pragma mark - UITableViewDelegate

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{

    return 50;

}

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

{

    _selected[indexPath.row] = !_selected[indexPath.row];

    

    [tableView reloadData];

    

    

}

- (void)didReceiveMemoryWarning

{

    [superdidReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  UITableView 多选