【发布时间】:2014-11-18 11:56:52
【问题描述】:
我在单击按钮时实现了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"];
}
}
【问题讨论】:
-
发送删除码
-
你去 :) @RameshMuthe
-
你的代码没问题。你在这个控制器中使用了任何手势吗?
-
只需在视图控制器上点击手势识别器即可关闭键盘@RameshMuthe
-
一段时间去掉点击手势,看看有没有用?
标签: ios objective-c uitableview editmode