1
我很沮喪地知道,一種方法在iOS模擬器中工作正常,但在iPhone中無法正常工作。我正在使用iPhone 4S。方法不在iPhone中調用,但在iOS模擬器中調用
我想要做的是,我想添加「編輯」按鈕,而不是「刪除」按鈕。我正在使用下面的代碼 -
-(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上運行它,然後它顯示「刪除」按鈕,而不是「編輯」。見screenshot-
我無法理解什麼可以在代碼中可能的問題。當我在「editActionsForRowAtIndexPath」中放置一個斷點時,它不會被iPhone命中,但會被模擬器擊中。
如果有人知道這個問題,請幫助我。
在此先感謝。
設備的版本是什麼?作爲「editActionsForRowAtIndexPath」在iOS 8.0及更高版本中可用。 – Sujania
@Sujania好的..我還沒有檢查舊版本的可用性。我剛剛檢查了我的設備的版本,即7.1.2。意味着它不適用於這個版本..對嗎? – Abhinav
是的..請參閱:https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableViewDelegate_Protocol/#//apple_ref/occ/intfm/UITableViewDelegate/tableView:editActionsForRowAtIndexPath: – Sujania