UITable编辑二

1.气泡的使用

//哪些row显示长按气泡

- (BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath{

if (indexPath.row == 0) {//0的位置不能显示气泡

return NO;

}

return YES;

}

//有哪些气泡按钮

- (BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender{

if (action == @selector(paste:)) {

return NO;

}

return YES;

}

//当用户点击了气泡的按钮,实现什么方法

-(void)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender{

if (action == @selector(cut:)) {

NSLog(@"用户点击了剪切操作");

}

}

2.左滑动显示多个按钮

- (nullable NSArray*)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath{

UITableViewRowAction *unReadAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"标为未读" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {

NSLog(@"标记第%ld行未读", indexPath.row);

_tableView.editing = NO;

}];

UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"删除" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {

NSLog(@"删除第%ld行", indexPath.row);

}];

return @[deleteAction, unReadAction];

}

3.已经选中,已经取消

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

//当前tableView是编辑状态, 那么选中的行要加入到被编辑数组里

if (tableView.isEditing) {

[self.editedIndexPaths addObject:indexPath];

}

}

- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{

//被取消选中时,如果表格是编辑状态,那么从编辑列表中删除

if (tableView.isEditing) {

[self.editedIndexPaths removeObject:indexPath];

}

}

4.编辑类型

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{

if (indexPath.row == 0) {

//默认, 只有是这个属性,才能够左滑动出现多按钮

return UITableViewCellEditingStyleDelete;

}

return UITableViewCellEditingStyleDelete|UITableViewCellEditingStyleInsert;

}

#pragma mark - 方法 Methods

- (void)changeSegment:(UISegmentedControl *)sender{

NSLog(@"");

[self.tableView setEditing:sender.selectedSegmentIndex animated:YES];

if (sender.selectedSegmentIndex) {

//编辑状态 == 1

for (NSIndexPath *indexPath in self.editedIndexPaths) {

//通过代码选中cell的某一项, 使用代码调用不会触发协议方法

[self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];

}

}

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1.nav1.navigationBar.barStyle=UIBarStyleBlack; //改变导航栏背景颜...
    SadMine阅读 5,661评论 1 4
  • 概述在iOS开发中UITableView可以说是使用最广泛的控件,我们平时使用的软件中到处都可以看到它的影子,类似...
    liudhkk阅读 12,968评论 3 38
  • 版权声明:未经本人允许,禁止转载. 1. TableView初始化 1.UITableView有两种风格:UITa...
    萧雪痕阅读 7,910评论 2 10
  • *7月8日上午 N:Block :跟一个函数块差不多,会对里面所有的内容的引用计数+1,想要解决就用__block...
    炙冰阅读 7,330评论 1 14
  • 流转的世界,记住很多,最后遗忘很多。 怦然心动,不过是个开始,一种情愫,美好的心情,靓丽的感动。 进一步或许爱情也...
    呼吸的鲸鱼阅读 1,079评论 0 0