#pragma mark -- UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (self.delegate && [self.delegate respondsToSelector:@selector(editWords:dic:)]) {
[self.delegate editWords:self.canEditing dic:self.dataArr[indexPath.row]];
}
}
// 删除
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleDelete;
}
// 改变删除按钮的title
-(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
{
return @"删除";
}
// 是否可以左滑删除
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
if (self.canEditing == can) {
return YES;
}
return NO;
}
// 删除用到的函数
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
[TeacherRequestM paperDeleteWorkworkId:[self.dataArr[indexPath.section] getStringValueForKey:@"id" defaultValue:@" "] SuccessBlock:^{
NSMutableArray *copy=[self.dataArr mutableCopy];
[copy removeObjectAtIndex:indexPath.row]; //删除数组里的数据
self.dataArr = copy;
[self.tableV deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];//删除对应数据的cell
[self.tableV reloadData];
} failBlock:^(NSError *error) {
}];
}
}
#pragma mark -- UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return self.dataArr.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
NSDictionary *dic = self.dataArr[indexPath.row];
NSString *CellIdentifier = [NSString stringWithFormat:@"%@%@",StudentDissertationInfoCellIdentifer,[dic getStringValueForKey:@"id" defaultValue:nil]];
StudentDissertationInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
cell = [[StudentDissertationInfoCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.dic = dic;
return cell;
}
// 添加整个tableV
[self addSubview:self.tableV];
self.tableV.tableHeaderView = self.teacherTableHeaderV;
self.tableV.tableFooterView = footerV;
__weak typeof(self) weakSelf = self;
self.tableV.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
[weakSelf initData];
}];
self.tableV.mj_header.lastUpdatedTimeKey = @"StudentDissertationV";
[self.tableV.mj_header beginRefreshing];
// 整个tableV
-(UITableView *)tableV{
if (!_tableV) {
_tableV = [[UITableView alloc]initWithFrame:CGRM(0,0, S_W,self.height)];
_tableV.backgroundColor = DefaultBackGroundColor;
_tableV.delegate = self;
_tableV.dataSource = self;
_tableV.showsHorizontalScrollIndicator = NO;
_tableV.contentInset = UIEdgeInsetsMake(0, 0,10, 0);
_tableV.separatorColor = [UIColor clearColor];
_tableV.allowsSelectionDuringEditing = YES;
}
return _tableV;
}
iOS - UITableView 新建、删除
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- - (BOOL)tableView:(UITableView *)tableView canEditRowAtIn...
- http://www.jb51.net/article/80785.htm 1.第一种创建的cell的方法,系统提...
- 一、概述 UITbableView作为列表展示信息,除了展示的功能,有时还会用到删除,比如购物车、收藏列表等。 单...