2016-12-23 37 views
1
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) { 
} 

func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { 
    return true 
} 

func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? { 
    let more = UITableViewRowAction(style: .normal, title: "More") { action, index in 
     print("more button tapped") 
    } 
    more.backgroundColor = UIColor.lightGray 

    let favorite = UITableViewRowAction(style: .normal, title: "Favorite") { action, index in 
     print("favorite button tapped") 
    } 
    favorite.backgroundColor = UIColor.orange 

    let share = UITableViewRowAction(style: .normal, title: "Share") { action, index in 
     print("share button tapped") 
    } 
    share.backgroundColor = UIColor.blue 

    return [share, favorite, more] 
} 

我插入這個代碼來創建一些行動上做一個Cell,但是當我運行該項目,我嘗試刷卡的單元格可能只有動作是Delete滑動操作上的UITableViewCell

我該如何解決這個問題?

+0

所以,你不能看到刷卡上的所有選項,或者你看到的按鈕,但竊聽不工作呢? –

+0

@ManishPathak我無法看到所有選項。我只能看到選項「刪除」 – DanieleLanari

+0

Nirav的答案是否解決了您的問題? –

回答

2

tableView(_:editActionsForRowAt:)的簽名在Swift 3中更改爲如下所示。因此,只需將您的editActionsForRowAt替換爲下面的一個即可。

func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? { 

    let more = UITableViewRowAction(style: .normal, title: "More") { action, index in 
     print("more button tapped") 
    } 
    more.backgroundColor = UIColor.lightGray 

    let favorite = UITableViewRowAction(style: .normal, title: "Favorite") { action, index in 
     print("favorite button tapped") 
    } 
    favorite.backgroundColor = UIColor.orange 

    let share = UITableViewRowAction(style: .normal, title: "Share") { action, index in 
     print("share button tapped") 
    } 
    share.backgroundColor = UIColor.blue 

    return [share, favorite, more] 
}