swift – editActionsForRowAtIndexPath不能在iOS 8上使用Xcode 7执行

前端之家收集整理的这篇文章主要介绍了swift – editActionsForRowAtIndexPath不能在iOS 8上使用Xcode 7执行前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在3台设备上测试我的应用程序. iOS 9上的2个设备和iOS 8上的一个设备.在iOS 9上,当我滑动一个单元格时,editActionsForRowAtIndexPath的功能正在运行,并且显示动作.但是在iOS 8中,我无法滑动单元格.

这是我的代码

  1. func tableView(tableView: UITableView,editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
  2. let ShareAction = UITableViewRowAction(style: .Normal,title: "Partager",handler: { (action: UITableViewRowAction!,indexPath: NSIndexPath!) -> Void in
  3. if AllArticle[indexPath.row].Title != nil && AllArticle[indexPath.row].Link != nil {
  4. var ToShare = []
  5. if self.search {
  6. ToShare = [ArticleFiltered[indexPath.row].Link!]
  7. } else {
  8. ToShare = [AllArticle[indexPath.row].Link!]
  9. }
  10. let ActivityViewController = UIActivityViewController(activityItems: ToShare as [AnyObject],applicationActivities: nil)
  11. self.presentViewController(ActivityViewController,animated: true,completion: {
  12. self.TableView.setEditing(false,animated: true)
  13. })
  14. }
  15. })
  16.  
  17. let FavoriteAction = UITableViewRowAction(style: .Normal,title: "Ajouté aux favoris",indexPath: NSIndexPath!) -> Void in
  18.  
  19. if AllArticle[indexPath.row].Favoris {
  20. let alreadyInView = UIAlertController(title: "Favori déjà ajouté",message: "Cet article fait déjà parti de vos favoris",preferredStyle: .Alert)
  21. let ActionAlert = UIAlertAction(title: "Ok",style: .Default) { (action) in }
  22. alreadyInView.addAction(ActionAlert)
  23. self.presentViewController(alreadyInView,completion: nil)
  24. } else {
  25. AllArticle[indexPath.row].Favoris = true
  26. let alreadyInView = UIAlertController(title: "Favori ajouté",message: "Cet article fait maintenant parti de vos favoris",completion: nil)
  27. Favorite.append(indexPath.row)
  28. saveFavoris()
  29. }
  30. self.TableView.setEditing(false,animated: true)
  31. })
  32.  
  33. FavoriteAction.backgroundColor = UIColor.redColor()
  34.  
  35. return [ShareAction,FavoriteAction]
  36. }

当然我加入了

viewDidLoad中()

  1. if TableView != nil {
  2. TableView.delegate = self
  3. TableView.dataSource = self
  4. TableView.tableFooterView = UIView(frame: CGRectZero)
  5. TableView.addGestureRecognizer(UITapGestureRecognizer(target: self,action: "tapTableView"))
  6. TableView.gestureRecognizers?.last?.delegate = self
  7. }

可能它的Xcode错误
有任何想法吗 ?

谢谢 !

在iOS 8下,只有在委托中实现了commitEditingStyle调用时,才能启用editActions.在tableViewController中添加bellow方法
  1. - (void)tableView:(UITableView*)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath*)indexPath
  2. {
  3. // All tasks are handled by blocks defined in editActionsForRowAtIndexPath,however iOS8 requires this method to enable editing
  4. }

猜你在找的Swift相关文章