标签:
1.Push跳转
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellKey=@"cellKey"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellKey ]; if (cell==nil) { cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellKey]; } NSString *content=[list objectAtIndex:indexPath.row]; cell.textLabel.text=content; cell.accessoryType=UITableViewCellAccessoryDetailButton; return cell; } - (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath { NSString *content=[list objectAtIndex:indexPath.row]; CellDetail *detail=[[CellDetail alloc]initWithNibName:@"CellDetail" bundle:[NSBundle mainBundle]]; [self.navigationController pushViewController:detail animated:YES]; // detail.label.text=[NSString stringWithFormat:@"我要去%@旅游",content]; [detail setLabel:[NSString stringWithFormat:@"我要去%@旅游",content]]; }
2.打勾选中的样式
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellKey=@"cellKey"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellKey]; if (cell==nil) { cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellKey]; } cell.textLabel.text=[list objectAtIndex:indexPath.row]; if (indexPath.row==markedIndexPath.row&&markedIndexPath) { cell.accessoryType=UITableViewCellAccessoryCheckmark; } else { cell.accessoryType=UITableViewCellAccessoryNone; } // Configure the cell... return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { self.markedIndexPath=indexPath; //[self.tableView reloadData]; NSArray *array=[NSArray arrayWithObjects:indexPath, nil]; [self.tableView reloadRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationFade]; [self.tableView reloadData]; }
3.移动
- (void)viewDidLoad { [super viewDidLoad]; // Uncomment the following line to preserve selection between presentations. // self.clearsSelectionOnViewWillAppear = NO; // Uncomment the following line to display an Edit button in the navigation bar for this view controller. // self.navigationItem.rightBarButtonItem = self.editButtonItem; NSMutableArray *array=[NSMutableArray arrayWithObjects:@"现代依兰特",@"法拉利612",@"路虎",@"标致",@"玛莎拉蒂",@"奥迪R8",@"美洲虎", nil]; self.list=array; UIBarButtonItem *moveButton=[[UIBarButtonItem alloc]initWithTitle:@"移动" style:UIBarButtonItemStyleDone target:self action:@selector(Move)]; self.navigationItem.rightBarButtonItem=moveButton; } - (void)Move { [self.tableView setEditing:!self.tableView.editing animated:YES]; if (self.tableView.editing) { [self.navigationItem.rightBarButtonItem setTitle:@"完成"]; } else { [self.navigationItem.rightBarButtonItem setTitle:@"移动"]; } } - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { //禁止编辑 return UITableViewCellEditingStyleNone; } - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath { NSString *car=[list objectAtIndex:sourceIndexPath.row]; [list removeObjectAtIndex:sourceIndexPath.row]; [list insertObject:car atIndex:destinationIndexPath.row]; } - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { return YES; }
4.删除
- (void)viewDidLoad { [super viewDidLoad]; // Uncomment the following line to preserve selection between presentations. // self.clearsSelectionOnViewWillAppear = NO; // Uncomment the following line to display an Edit button in the navigation bar for this view controller. // self.navigationItem.rightBarButtonItem = self.editButtonItem; NSMutableArray *array=[[NSMutableArray alloc]initWithObjects:@"牡丹花",@"莲花",@"含羞草",@"月季花",@"恐龙",@"猫",@"海参", nil]; self.list=array; UIBarButtonItem *deleteButton=[[UIBarButtonItem alloc]initWithTitle:@"删除" style:UIBarButtonItemStyleBordered target:self action:@selector(Delete)]; self.navigationItem.rightBarButtonItem=deleteButton; } - (void)Delete { [self.tableView setEditing:!self.tableView.editing animated:YES]; if (self.tableView.editing) { [self.navigationItem.rightBarButtonItem setTitle:@"完成"]; }else { [self.navigationItem.rightBarButtonItem setTitle:@"删除"]; } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle==UITableViewCellEditingStyleDelete) { [list removeObjectAtIndex:indexPath.row]; NSArray *array=[[NSArray alloc]initWithObjects:indexPath, nil]; [tableView deleteRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationMiddle]; } }
标签:
原文地址:http://www.cnblogs.com/iOS-Code/p/4709131.html