2015-08-28 30 views
13

Tôi đang thử nghiệm ứng dụng của mình trên 3 thiết bị. 2 thiết bị trên iOS 9 và một thiết bị trên iOS 8. Trên iOS 9, chức năng editActionsForRowAtIndexPath đang hoạt động và hành động được hiển thị khi tôi vuốt một ô. Nhưng trên iOS 8, tôi không thể vuốt các ô.editActionsForRowAtIndexPath không thực thi trên iOS 8 với Xcode 7

Đây là mã của tôi:

func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? { 
    let ShareAction = UITableViewRowAction(style: .Normal, title: "Partager", handler: { (action: UITableViewRowAction!, indexPath: NSIndexPath!) -> Void in 
     if AllArticle[indexPath.row].Title != nil && AllArticle[indexPath.row].Link != nil { 
      var ToShare = [] 
      if self.search { 
       ToShare = [ArticleFiltered[indexPath.row].Link!] 
      } else { 
       ToShare = [AllArticle[indexPath.row].Link!] 
      } 
      let ActivityViewController = UIActivityViewController(activityItems: ToShare as [AnyObject], applicationActivities: nil) 
      self.presentViewController(ActivityViewController, animated: true, completion: { 
       self.TableView.setEditing(false, animated: true) 
      }) 
     } 
    }) 

    let FavoriteAction = UITableViewRowAction(style: .Normal, title: "Ajouté aux favoris", handler: { (action: UITableViewRowAction!, indexPath: NSIndexPath!) -> Void in 

     if AllArticle[indexPath.row].Favoris { 
      let alreadyInView = UIAlertController(title: "Favori déjà ajouté", message: "Cet article fait déjà parti de vos favoris", preferredStyle: .Alert) 
      let ActionAlert = UIAlertAction(title: "Ok", style: .Default) { (action) in } 
      alreadyInView.addAction(ActionAlert) 
      self.presentViewController(alreadyInView, animated: true, completion: nil) 
     } else { 
      AllArticle[indexPath.row].Favoris = true 
      let alreadyInView = UIAlertController(title: "Favori ajouté", message: "Cet article fait maintenant parti de vos favoris", preferredStyle: .Alert) 
      let ActionAlert = UIAlertAction(title: "Ok", style: .Default) { (action) in } 
      alreadyInView.addAction(ActionAlert) 
      self.presentViewController(alreadyInView, animated: true, completion: nil) 
      Favorite.append(indexPath.row) 
      saveFavoris() 
     } 
     self.TableView.setEditing(false, animated: true) 
    }) 

    FavoriteAction.backgroundColor = UIColor.redColor() 

    return [ShareAction, FavoriteAction] 
} 

Và dĩ nhiên là tôi thêm vào trong

viewDidLoad()

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

May lỗi Xcode của nó? Bất kỳ ý tưởng nào?

Cảm ơn!

+0

Tôi gặp sự cố tương tự. Tất cả hoạt động tốt trên iOS 9 nhưng không phải trên 8. –

+0

Chủ nhân Vàng của Xcode có sửa lỗi này không? –

+0

Lỗi vẫn còn ở đây với Xcode GM, có thể đó là prog của chúng tôi –

Trả lời

41

Trong Chỉnh sửa iOS 8 chỉ được bật nếu lệnh commitEditingStyle được triển khai trong đại biểu của bạn. Thêm phương pháp dưới đây trong tableViewController của bạn:

- (void)tableView:(UITableView*)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath*)indexPath 
{ 
    // All tasks are handled by blocks defined in editActionsForRowAtIndexPath, however iOS8 requires this method to enable editing 
} 
0

Nếu bạn có tùy chỉnh UITableViewCell, và có có một GestureRecognizer, kiểm tra các phương pháp đại biểu - shouldRecognizeSimultaneouslyWithGestureRecognizer:

+0

Chào mừng bạn đến với StackOverflow. Câu trả lời của bạn có vẻ hơi không rõ ràng, bạn có muốn xây dựng nó không? Vui lòng mô tả những phương pháp mà bạn đang nói đến làm hoặc chỉ ra cách áp dụng chúng vào trường hợp của OP. – YakovL

0

Thêm phương pháp đại biểu này đến lớp.

func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) { 
     if editingStyle == UITableViewCellEditingStyle.Delete { 
    } 
} 
Các vấn đề liên quan