项目介绍:
自定义tabelViewCell侧滑删除按钮(可调整宽度)
主要实现代码:
[Objective-C] 查看源文件 复制代码
#import "ViewController.h"
#import "BLTableViewCell.h"
@interface ViewController ()<CellButtonEventViewDelegate,UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) NSMutableArray *dataArray;
@property (nonatomic, strong) UITableView *tableview;
@end
@implementation ViewController
- (NSMutableArray *)dataArray{
if (!_dataArray) {
_dataArray = [NSMutableArray arrayWithArray:@[@"这是第一行",@"这是第2行",@"这是第3行",@"这是第4行",@"这是第5行",@"这是第6行",@"这是第7行",@"这是第8行",@"这是第9行"]];
}
return _dataArray;
}
- (void)viewDidLoad {
[super viewDidLoad];
_tableview = [[UITableView alloc]init];
_tableview.delegate = self;
_tableview.dataSource = self;
[self.view addSubview:_tableview];
_tableview.frame = self.view.bounds;
_tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
_tableview.backgroundColor = [UIColor orangeColor];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return self.dataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
BLTableViewCell *cell = [BLTableViewCell cellWithTableView:tableView];
cell.delegate = self;
cell.textLabel.text = self.dataArray[indexPath.row];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 60;
}
//实现代理方法
- (void)deleteCell:(BLTableViewCell *)cell{
NSIndexPath *indexpath = [self.tableview indexPathForCell:cell];
[self.dataArray removeObjectAtIndex:indexpath.row];
[self.tableview deleteRowsAtIndexPaths:@[indexpath] withRowAnimation:UITableViewRowAnimationLeft];
}
-(void)closeOtherCellLeftSwipe
{
//循环显示的cell
for (BLTableViewCell *item in self.self.tableview.visibleCells) {
[item closeSwipe];
}
}
@end

自定义cell侧滑删除按钮2.zip
(34.07 KB, 下载次数: 618)
2016-7-11 20:43 上传
点击文件名下载附件
