Jon*_*Jon 0 iphone cocoa-touch objective-c uitableview
我有一个表,目前可以刷卡删除.我想在导航栏中有一个编辑按钮,以便用户可以更改单元格的标题文本.
到目前为止我有这个但没有任何反应
UIBarButtonItem * editButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(setEditing:animated:)];
[self.navigationItem setLeftBarButtonItem:editButton];
[editButton release];
- (void)setEditing:(BOOL)editing animated:(BOOL)animate
{
[super setEditing:editing animated:animate];
if(editing)
{
NSLog(@"editMode on");
}
else
{
NSLog(@"Done leave editmode");
}
}
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
// Delete the managed object for the given index path
NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];
[context deleteObject:[self.fetchedResultsController objectAtIndexPath:indexPath]];
NSLog(@"fetched results : \n%@\n",[self.fetchedResultsController fetchedObjects]);
// Commit the change.
NSError *error = nil;
// Update the array and table view.
if (![managedObjectContext save:&error])
{
// Handle the error.
}
}
}
Run Code Online (Sandbox Code Playgroud)
只需拥有或取消注释viewDidLoad:
self.navigationItem.rightBarButtonItem = self.editButtonItem;
Run Code Online (Sandbox Code Playgroud)
并实施
- (void)setEditing:(BOOL)editing animated:(BOOL)animate
{
if(editing)
{
NSLog(@"editMode on");
}
else
{
NSLog(@"Done leave editmode");
}
[super setEditing:editing animated:animate];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3505 次 |
| 最近记录: |