2015-10-04 55 views
0

我有以下代碼會照顧在tableViewCell中正確的滑動,它的工作正常時,用戶右滑動正確的單元格有討論ROOT,如果用戶右滑動單元格沒有這個URL,那麼UITableViewRowAction返回一個空數組。好的,選擇一個沒有URL的單元格後,我無法選擇任何其他tableViewCell,我甚至不能正確滑動。我知道我錯過了一些東西。UITableViewRowAction行爲不可預測

請幫我解決。

func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? { 
    let discussion = UITableViewRowAction(style: .Normal, title: "Discussion") { action, index in 
     self.loadTheDiscussionPageInWebViewController(indexPath.section, index: indexPath.row) 
    } 

    if let _ = self.allDatas[indexPath.section][indexPath.row].discussionUrl { 
     print(" BUTTON \(discussion)") 

     return [discussion] 
    } else { 
     print("NO BUTTON") 

     return [] 
    } 
} 

回答

0

不返回空動作數組。請改爲使用tableView:indexPath:函數僅爲您的單元格返回true,其中包含討論URL。像這樣的東西(以下保證return語句返回Bool):

func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool { 
    return self.allDatas[indexPath.section][indexPath.row].discussionUrl 
} 

然後打電話給你的editActionsForRowAtIndexPath這樣的:

func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? { 
    let discussion = UITableViewRowAction(style: .Normal, title: "Discussion") { action, index in 
    self.loadTheDiscussionPageInWebViewController(indexPath.section, index: indexPath.row) 
    return [discussion] 
}