1.tableview创建
**//测试数组
self.dateArray = [NSMutableArray arrayWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9", nil];
//设置tableview
self.myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 52, self.view.width, self.view.height)];
self.myTableView.delegate = self;
self.myTableView.dataSource = self;
self.myTableView.backgroundColor = RGBCOLOR(239, 240, 241);
//取消cell线
//self.myTableView.separatorStyle = UITableViewCellSelectionStyleNone;
//self.myTableView.editing = NO;
[self.view addSubview:self.myTableView];
**
2.tableview代理函数
#pragma mark 设置行数 rows
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.dateArray.count;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
![图片展示1](http://img.blog.csdn.net/20161111112142105)
#pragma mark 创建tableviewcell
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *myCell = @"mycell";
MyCollectTabView *cell = [tableView dequeueReusableCellWithIdentifier:myCell];
if (cell == nil) {
cell = [[MyCollectTabView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:myCell];
}
//cell的点击效果
//cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
#pragma mark 允许对cell进行编辑
-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
//cell 编辑设置
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
[self.dateArray removeObjectAtIndex:indexPath.row];
[self.myTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[tableView endUpdates];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
}
}
#pragma mark 点击tableviewcell
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"点击第几行 row == %ld",indexPath.row);
}
#pragma mark 设置cell高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return FIXWIDTHORHEIGHT(90);
}
3.自己创建一个全选按钮,我只给一个调用的函数
-(void)btnAllSelectAction:(UIButton *)sender
{
sender.backgroundColor = RGBCOLOR(239, 240, 241);
//通过遍历所有并选择
for (int row=0; row<10; row++) {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:0];
[self.myTableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
}
}
4.删除就把数据的data数组清空就可以了,如果不是全部要用数组记录一下
**
有一个需要注意的地方,全选时候内容整体向右滑动一小块
就是把tableviewcell中的img或者label 都放在 cell的 contentView上面就好了
**