2015-07-13 24 views
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]; 
} 

當我在模擬器中運行它,然後它工作正常。見截圖:

This is what working on simulator.

當我在iPhone上運行它,然後它顯示「刪除」按鈕,而不是「編輯」。見screenshot-

enter image description here

我無法理解什麼可以在代碼中可能的問題。當我在「editActionsForRowAtIndexPath」中放置一個斷點時,它不會被iPhone命中,但會被模擬器擊中。

如果有人知道這個問題,請幫助我。

在此先感謝。

+0

設備的版本是什麼?作爲「editActionsForRowAtIndexPath」在iOS 8.0及更高版本中可用。 – Sujania

+0

@Sujania好的..我還沒有檢查舊版本的可用性。我剛剛檢查了我的設備的版本,即7.1.2。意味着它不適用於這個版本..對嗎? – Abhinav

+0

是的..請參閱:https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableViewDelegate_Protocol/#//apple_ref/occ/intfm/UITableViewDelegate/tableView:editActionsForRowAtIndexPath: – Sujania

回答

2

對於5至8個所有iOS,使用MGSwipeTableCell

測試在iPhone和iPad所有IOS版本:iOS 5中,iOS 6中,7的iOS和iOS 8.

雖然MGSwipeTableCell不是直接回應editActionsForRowAtIndexPath只適用於iOS 8+,這是一個合理的選擇。它還允許多個按鈕和多個滑動方向。

相關問題