editButton = [[UIBarButtonItem alloc] initWithTitle:@”编辑” style:UIBarButtonItemStyleBordered target:self action:@selector(editAction)];
self.navigationItem.rightBarButtonItem = editButton;
}
-(void)ToReturn
{
[self.navigationController popViewControllerAnimated:YES];
}
- (void)editAction{
if (editButton.title == @”编辑”) {
[editButton setTitle:@"确定"];
[editButton setStyle:UIBarButtonItemStyleDone];
[self.roadTable setEditing:YES animated:YES];
}
else {
[editButton setTitle:@"编辑"];
[editButton setStyle:UIBarButtonItemStylePlain];
[self.roadTable setEditing:NO animated:YES];
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.titleArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @”Cell”;
UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.textLabel.text = [titleArray objectAtIndex:indexPath.row];
return cell;
}
//删除一行
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
//删除数组中的一条记录
[roadArray removeObjectAtIndex:indexPath.row -1];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
else if (editingStyle == UITableViewCellEditingStyleInsert)
{
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
}
}