UITableView doesn't go into editing mode and it doesn't edit!
I'm hardly working on a new project. The main structure is a tableView in the RootViewController, where some rows shows the actual statuses and some informations to the user. I'm now working on the editing mode which won't work.
In the navigationbar is a button which calls edit
here's the code:
- (void)edit {
NSLog(@"Edit pressed");
if (edit) {
NSLog(@"Deactivate edit\n");
edit = NO;
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Bearbeiten" style:UIBarButtonItemStyleBordered target:self action:@selector(edit)];
[contentTableView setEditing:NO animated:YES];
} else {
NSLog(@"Activate edit\n");
edit = YES;
开发者_Python百科 self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Fertig" style:UIBarButtonItemStyleDone target:self action:@selector(edit)];
[contentTableView setEditing:YES animated:YES];
}
}
My viewController is a subclass of UITableViewController
and the contentTableView
is not nil... I implemented the following methods:
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath {
NSMutableDictionary *oldDict = [[NSMutableDictionary alloc] initWithDictionary:[saver read]];
NSDictionary *movingDict = [[oldDict objectForKey:@"content"] objectAtIndex:sourceIndexPath.row];
[[oldDict objectForKey:@"content"] removeObjectAtIndex:sourceIndexPath.row];
[[oldDict objectForKey:@"content"] insertObject:movingDict atIndex:destinationIndexPath.row];
[saver write:oldDict];
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
NSMutableDictionary *oldDict = [[NSMutableDictionary alloc] initWithDictionary:[saver read]];
[[oldDict objectForKey:@"content"] removeObjectAtIndex:indexPath.row];
[saver write:oldDict];
[contentTableView beginUpdates];
[contentTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; //This doesn't work!
[contentTableView endUpdates];
}
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
return @"Entfernen";
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
I copied this from another Project and changed some parts of code but the main things I didn't touch!
What happens?
When I press Edit ('Bearbeiten') the function "edit" gets called. It replaces the button with Done ('Fertig') and writes the correct log:
> 2011-04-27 13:35:44.338 MyApp[1113:207] Edit pressed
> 2011-04-27 13:35:44.339 MyApp[1113:207] Activate edit
If I slide on a cell, the button Remove ('Entfernen') appears and when I press it, the button disappears but the row is still there, but it's removed from the content.
Does anyone know where I'm doing something wrong or where I forgot something?
Thanks in advance, mavrick3.
Edit 1:
I forgot to say: The method [tableView reloadData];
doesn't call numberOfRowsInSection
...
Those problems seems to be a bug in the iOS Simulator running iOS 4.3.2.
If you figured out this problem, please set your Deployment Target to an older SDK e.g. 4.2 and run your application on it.
精彩评论