为什么我写删除UITableView行的代理时快递出了问题题

iOS开发之tableView实现左滑删除功能
作者:IOSMan
字体:[ ] 类型:转载 时间:
我们在使用一些应用的时候,在滑动一些联系人的某一行的时候,会出现删除、置顶、更多等等的按钮,下面这篇文章主要就介绍了iOS用tableView实现左划删除功能的方法,有需要的朋友们可以参考借鉴,下面来一起看看吧。
这几天要实现左划删除的功能,发现网上很多帖子大多出自一人之手,然后都是 copy 的文章,其实都没有那么复杂,只实现一个代理方法就可以了
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
if (editingStyle == UITableViewCellEditingStyleDelete) {
// 删除数据源的数据,self.cellData是你自己的数据
[self.cellData removeObjectAtIndex:indexPath.row];
// 删除列表中数据
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
默认删除的文字为 Delete,要改为中文实现
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
return @"删除";//默认文字为 Delete
下面这两个代理方法不用写也可以,默认就是这样
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewCellEditingStyleD
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
return YES;
如果你报了这个错误:
'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (5) must be equal to the number of rows contained in that section before the update (5), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out)
你把代理方法中这两个方法顺序搞混了,先删除数据,再删除 cell
[self.cellData removeObjectAtIndex:indexPath.row];这个方法在前
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];这个方法在后
还有就是,别2到没设置代理,tableView.delegate =
以上就是关于iOS利用tableView实现左划删除功能的全部内容了,希望本文的内容对给iOS开发者们能有一定的帮助,如果有疑问大家可以留言交流。
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具iOS --- 去掉UITableView中的空白行 - 简书
iOS --- 去掉UITableView中的空白行
UITableView中默认将空白行也显示出来, 而只需要这句代码即可将其去掉:self.tableView.tableFooterView=UIView(frame: CGRectZero)更多iOS内容, 欢迎查看.主题 : UITableView 去除空的Cell
级别: 新手上路
可可豆: 44 CB
威望: 50 点
在线时间: 74(时)
发自: Web Page
UITableView 去除空的Cell&&&
& 我使用UITableView Plan样式,创建了4行Cell ,如下图所示,我只创建了4行,但是下面还是有很多空的cell,点击那些空的cell也没有任何反应,我想问我怎么样可以把那些空的cell去掉或者把那些下面的空的下划线去掉也可以 就只显示我创建的行数。
级别: 精灵王
UID: 96152
可可豆: 3763 CB
威望: 2865 点
在线时间: 2775(时)
发自: Web Page
去掉分割线,或者分割线的颜色,在cell中自己创建一个分割线
tableView.separatorColor = [UIColor clearColor];
或者
table.separatorStyle = UITableViewCellSeparatorStyleN
级别: 新手上路
UID: 131368
可可豆: 131 CB
威望: 51 点
在线时间: 335(时)
发自: Web Page
如果要保留分割线 用这个: tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
可可豆: * CB
威望: * 点
在线时间: (时)
注册时间: *
最后登录: *
发自: Web Page
你tabview太大了把。 设置小一点应该就可以了
级别: 新手上路
可可豆: 44 CB
威望: 50 点
在线时间: 74(时)
发自: Web Page
你这个方法是把所有的分割线去掉了,但是我要的效果是 前面4行的分割线还是要保留,其余空白的cell的分割线全部去掉 wechat 50 秒
级别: 侠客
UID: 219336
可可豆: 1356 CB
威望: 823 点
在线时间: 237(时)
发自: Web Page
//指定有多少个分区(Section),默认为1
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return [youArray count];//return 1;
}
//指定每个分区中有多少行,默认为1
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [youArray count];//return 4;
}
级别: 新手上路
UID: 166173
可可豆: 13 CB
威望: 6 点
在线时间: 60(时)
发自: Web Page
去掉分割线。然后自己添加一条分割线上去。或者如果你的tableview是固定单元格的。那你就可以给tableview设置一个tableView.tableFooterView
级别: 新手上路
可可豆: 20 CB
威望: 10 点
在线时间: 159(时)
发自: Web Page
回 2楼(csz2136) 的帖子
这个可以,谢谢!
级别: 骑士
UID: 285806
可可豆: 1250 CB
威望: 845 点
在线时间: 488(时)
发自: Web Page
级别: 新手上路
可可豆: 3 CB
威望: 3 点
在线时间: 45(时)
发自: Web Page
2楼正确,设个空的footerview就好了
关注本帖(如果有新回复会站内信通知您)
发帖、回帖都会得到可观的积分奖励。
按"Ctrl+Enter"直接提交
关注CocoaChina
关注微信 每日推荐
扫一扫 关注CVP公众号
扫一扫 浏览移动版

我要回帖

更多关于 ipad亮度出了问题 的文章

 

随机推荐