单击按钮时,我已经实现UITableview
了编辑模式,但是每次进入编辑模式并且单击删除按钮时,都没有任何反应。我有一个视图控制器,UITableview
上面有一个。我已经设置了我的委托和 tableview 源以及我所有的编辑回调。一切正常(例如重新排序单元格),但是每当我尝试通过按下删除控制按钮进行删除时,删除按钮都不会出现。
我很绝望,因为这似乎是一个非常简单的问题,但无论我尝试什么,它似乎都不起作用。
这就是我实现编辑模式的方式
- (UITableViewCellEditingStyle) tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:
(NSIndexPath *)indexPath {
return UITableViewCellEditingStyleDelete;
}
- (BOOL) tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
- (void) tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
[favoriteCurrencyValueList removeObjectForKey:[favoriteCurrencyList objectAtIndex:indexPath.row]];
[favoriteCurrencyList removeObjectAtIndex:indexPath.row];
NSUserDefaults *defaultSettings = [NSUserDefaults standardUserDefaults];
[defaultSettings setObject:favoriteCurrencyList forKey:@"FavoriteCurrencies"];
[defaultSettings setObject:favoriteCurrencyValueList forKey:@"PastValues"];
[defaultSettings synchronize];
[self.favoriteCurrencyTable beginUpdates];
[self.favoriteCurrencyTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:(UITableViewRowAnimation)UITableViewRowAnimationLeft];
[self.favoriteCurrencyTable endUpdates];
}
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
indexPathSelected = indexPath;
//[self.view endEditing:YES];
}
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
[self.favoriteCurrencyList exchangeObjectAtIndex:sourceIndexPath.row withObjectAtIndex:destinationIndexPath.row];
[[NSUserDefaults standardUserDefaults] setObject:self.favoriteCurrencyList forKey:@"FavoriteCurrencies"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
这是设置编辑模式的原因
- (IBAction)editButtonPressed:(UIBarButtonItem *)sender {
if (self.editing && self.favoriteCurrencyTable.editing) {
self.editing = NO;
[self.favoriteCurrencyTable setEditing:NO animated:YES];
[self.editButton setTitle:@"Edit"];
}
else {
self.editing = YES;
[self.favoriteCurrencyTable setEditing:YES animated:YES];
[self.editButton setTitle:@"Done"];
}
}