TableViewのセルをスライドすると編集や削除などのアクションボタンを設定できる機能があります。
この度こちらを実装したのですが、
iPhoneSEではこのスライドがスラスラとできるのですが、
iPhone5(実機)だとスライドがうまくできず、動作が重い印象で、何回もスライドさせる動作をするとたまに出現する。という現象が起きています。
実装は下記の通りです。
canEditRowAtIndexPathで編集できるセルを設定
Swift
1override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool { 2 3 switch indexPath.section { 4 case 2: 5 //条件によってtrueかfalseを返す 6 case 3: 7 //条件によってtrueかfalseを返す 8 default: 9 return false 10 } 11 }
編集・削除のそれぞれの処理を設定
Swift
1override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? { 2 3 let myShareButton: UITableViewRowAction = UITableViewRowAction(style: .Normal, title: NSLocalizedString("Edit", comment: "Edit")) { (action, index) -> Void in 4 5 let commentsController = CommentsViewController() 6 let navigationController = LGSemiModalNavViewController(rootViewController: commentsController) 7 8 let screen = UIScreen.mainScreen() 9 navigationController.view.frame = CGRectMake(0, 0, screen.bounds.size.width, screen.bounds.size.height * 0.8) 10 11 commentsController.delegate = self 12 commentsController.comment = self.comments[indexPath.row] 13 commentsController.editFlg = true 14 commentsController.event = self.event 15 commentsController.userObject = self.userObject 16 17 self.nonEditComments = [] 18 19 if self.comments.count > 0 { 20 self.nonEditComments = self.comments 21 self.nonEditComments?.removeAtIndex(indexPath.row) 22 commentsController.eventComments = self.nonEditComments!.reverse() 23 } 24 25 self.presentViewController(navigationController, animated: true) { 26 commentsController.textView.becomeFirstResponder() 27 } 28 29 } 30 myShareButton.backgroundColor = UIColor.blueColor() 31 32 let myArchiveButton: UITableViewRowAction = UITableViewRowAction(style: .Normal, title: NSLocalizedString("Delete", comment: "Delete")) { (action, index) -> Void in 33 34 let hud = MBProgressHUD.showHUDAddedTo(self.view, animated: true) 35 hud.yOffset = Float(self.view.bounds.minY) 36 37 let url = "API" 38 39 Alamofire.request(.DELETE, url, encoding: .JSON) 40 .validate() 41 .responseData { response in Utils.checkResponse(response) } 42 .responseJSON { response in 43 hud.hide(true) 44 45 switch response.result { 46 case .Success: 47 48 self.loadObjects() 49 self.tableView!.reloadData() 50 51 case .Failure(let responsError): 52 print(responsError) 53 } 54 } 55 } 56 myArchiveButton.backgroundColor = UIColor.redColor() 57 58 return [myShareButton, myArchiveButton] 59 }
変わっている点といえばセルはxibファイル作成されています。
もし同じ現象に遭遇したという方がいらっしゃいましたら是非共有いただけますと助かります!
よろしくお願いいたします。
あなたの回答
tips
プレビュー