UITableView基本属性二:编辑模式
2015-09-06 14:29
423 查看
UITableView基本属性二 :
系统自带的
自定义后的
//设置分区头 -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { if (0 == section) { return @"男员工"; }else{ return @"女员工"; } } //设置左滑文字 - (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{ return @"解绑"; } //编辑模式 左边“+” “-” -(void)setEditing:(BOOL)editing animated:(BOOL)animated{ [super setEditing:editing animated:animated]; [self.tableView setEditing:editing animated:animated]; } -(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{ //删除男员工 if (editingStyle == UITableViewCellEditingStyleDelete) { [[self.allPerson objectAtIndex:indexPath.section]removeObjectAtIndex:indexPath.row]; //删除数据 [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationMiddle]; //删除行 } else{ NSLog(@"添加女员工"); TRpeson *newperson = [[TRpeson alloc]init]; newperson.no = 140801; newperson.name = @"新员工"; [[self.allPerson objectAtIndex:indexPath.section]insertObject:newperson atIndex:indexPath.row]; //添加数据 [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationRight]; //添加行 } } -(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{ if (0 == indexPath.section) { return UITableViewCellEditingStyleDelete; //删除 } else{ return UITableViewCellEditingStyleInsert; //添加 } }
//设置左边的“+”“-” - (void)viewDidLoad { self.editButtonItem.possibleTitles = [NSSet setWithObjects:@"编辑", @"完成", nil]; self.editButtonItem.title = @"编辑"; self.navigationItem.leftBarButtonItem = self.editButtonItem; } //编辑模式 -(void)setEditing:(BOOL)editing animated:(BOOL)animated{ [super setEditing:editing animated:animated]; [self.tableView setEditing:editing animated:animated]; // if (self.editing) { self.editButtonItem.title = @"完成"; } else { self.editButtonItem.title = @"编辑"; } }
#pragma mark 移动行 -(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath{ //拿到要移动的对象 TRpeson *person=[[self.allPerson objectAtIndex:sourceIndexPath.section]objectAtIndex:sourceIndexPath.row]; //删除原来的位置 [[self.allPerson objectAtIndex:sourceIndexPath.section]removeObjectAtIndex:sourceIndexPath.row]; //更新数据 [[self.allPerson objectAtIndex:destinationIndexPath.section]insertObject:person atIndex:destinationIndexPath.row]; [self.tableView reloadData]; }
//Cell点击事件 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"Cell被点击了"); UITableViewCell *ontcell=[tableView cellForRowAtIndexPath:indexPath];//拿到点击cell对象 if (ontcell.accessoryType==UITableViewCellAccessoryNone) { ontcell.accessoryType=UITableViewCellAccessoryCheckmark; }else{ ontcell.accessoryType=UITableViewCellAccessoryNone; [tableView deselectRowAtIndexPath:indexPath animated:YES]; //动画渐变 } /* cell.accessoryType = UITableViewCellAccessoryNone;//cell没有任何的样式 cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;//cell的右边有一个小箭头,距离右边有十几像素; cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;//cell右边有一个蓝色的圆形button; cell.accessoryType = UITableViewCellAccessoryCheckmark;//cell右边的形状是对号; UIImage *image= [UIImage imageNamed:@"delete.png"]; button = [UIButton buttonWithType:UIButtonTypeCustom]; CGRect frame = CGRectMake(0.0, 0.0, image.size.width, image.size.height); button.frame = frame; [button setBackgroundImage:imageforState:UIControlStateNormal]; button.backgroundColor= [UIColor clearColor]; cell.accessoryView= button; //自定义 */ }
系统自带的
自定义后的
相关文章推荐
- HBuilder的几个常用快捷键
- iOS-交互设计归纳
- codeforces 484 B Maximum Value 排序+二分 + 数学
- UI小组件 UISegment-UISlider-UIStepper-UIProgressView-UITextView介绍
- Java____Servlet(调用servlet初始化request、response与webclient进行通信服务)学习整理
- 1062. Talent and Virtue (25)
- ToStringBuilder学习(一):常用方法介绍
- UITableView的重用机制(缓存机制)
- Stack - Min Stack
- UI初级之界面特别处理技巧二
- UI初级之界面特殊处理技巧一
- UI初级之表视图UITableView自定义单元格
- ffmpeg: ‘UINT64_C’ was not declared in this scope (转)
- String详解, String和CharSequence区别, StringBuilder和StringBuffer的区别 (String系列之1)
- UI初级之常用UI控件UILabl 与 UIButton
- UI入门教程
- iOS开发:UITableView编辑——cell的删除和移动
- 聊聊并发——ConcurrentLinkedQueue的实现原理分析
- ui概述
- iOS-UILabel 自动换行