我很沮丧地知道一个方法在 iOS 模拟器中工作正常但在我的 iPhone 中不起作用。我使用的是 iPhone 4S。
我想做的是,我想在滑动时添加“编辑”按钮而不是“删除”按钮。我正在为此使用以下代码-
-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
return YES;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath{
}
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewRowAction *edit = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault
title:@"Edit"
handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
// Open Edit Screen
isEdited = YES;
if (isSearchResult) {
editArray = [NSMutableArray arrayWithObject:[searchResults objectAtIndex:indexPath.row]];
}
else{
editArray = [NSMutableArray arrayWithObject:[soArray objectAtIndex:indexPath.row]];
}
[self performSegueWithIdentifier:@"addCateChild" sender:nil];
}];
return @[edit];
}
当我在模拟器中运行它时,它工作正常。看截图:
当我在 iPhone 中运行它时,它会显示“删除”按钮而不是“编辑”按钮。看截图-
我无法理解代码中可能存在的问题。当我在“editActionsForRowAtIndexPath”中放置一个断点时,它不会被 iPhone 击中,但会被模拟器击中。
如果有人知道这个问题,请帮助我。
提前致谢。
最佳答案
对于从 5 到 8 的所有 iOS,使用 MGSwipeTableCell
Tested on all iOS versions on iPhone and iPad: iOS 5, iOS 6, iOS 7 and iOS 8.
虽然 MGSwipeTableCell
不是对仅在 iOS 8+ 中可用的 editActionsForRowAtIndexPath
的直接响应,但它是一个合理的替代方案。它还允许多个按钮和多个滑动方向。
关于ios - 方法不是在 iPhone 中调用而是在 iOS 模拟器中调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31376249/