本項目是《beginning iOS8 programming with swift》中的項目學習筆記==》所有筆記目錄html
------------------------------------------------------------------------------------------------------------------swift
1. 實現下面的方法,自動打開滑動刪除功能:ide
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) { }
2. 自定義右滑菜單項學習
override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? { // 分享項 let shareAction = UITableViewRowAction(style: .Default, title: "Share") { (action, indexPath) -> Void in // 選擇分享目標 let shareMenu = UIAlertController(title: nil, message: "Share using", preferredStyle: .ActionSheet) let twitterAction = UIAlertAction(title: "Twitter", style: .Default, handler: nil) let facebookAction = UIAlertAction(title: "Facebook", style: .Default, handler: nil) let emailAction = UIAlertAction(title: "Emain", style: .Default, handler: nil) let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil) shareMenu.addAction(twitterAction) shareMenu.addAction(facebookAction) shareMenu.addAction(emailAction) shareMenu.addAction(cancelAction) self.presentViewController(shareMenu, animated: true, completion: nil) } // 刪除項(實現了這個方法須要本身寫刪除項) let deleteAction = UITableViewRowAction(style: .Default, title: "Delete") { (action, indexPath) -> Void in // 從數據源中刪除 // ... self.tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade) } // 設置背景色 shareAction.backgroundColor = UIColor.orangeColor() deleteAction.backgroundColor = UIColor.blueColor() return [shareAction, deleteAction] }
效果圖:spa