2015-08-28 9 views
13

Ich teste meine Anwendung auf 3 Geräten. 2 Geräte auf iOS 9 und ein Gerät auf iOS 8. Auf iOS 9 funktioniert die Funktion editActionsForRowAtIndexPath und es wird eine Aktion angezeigt, wenn ich eine Zelle wische. Aber auf iOS 8 kann ich keine Zellen wischen.editActionsForRowAtIndexPath nicht unter iOS 8 mit Xcode 7

Hier ist mein Code:

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] 
} 

Und natürlich habe ich hinzugefügt in

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 
    } 

Mai seine Xcode Bug? Irgendwelche Ideen?

Danke!

+0

Ich habe das gleiche Problem. Es funktioniert alles auf iOS 9, aber nicht auf 8. –

+0

Hat der Gold Master von Xcode diesen Fehler behoben? –

+0

Fehler ist immer noch hier mit Xcode GM, vielleicht ist es unser Prog –

Antwort

41

Unter iOS 8 sind editActions nur aktiviert, wenn der commitEditingStyle-Aufruf in Ihrem Delegaten implementiert ist. Fügen Sie die unten Methode in dem Tableviewcontroller:

- (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

Wenn Sie benutzerdefinierte UITableViewCell haben, und es hat ein GestureRecognizer, überprüfen Sie die Delegatmethoden - shouldRecognizeSimultaneouslyWithGestureRecognizer:

+0

Willkommen bei StackOverflow. Ihre Antwort klingt etwas unspezifisch, würde es Ihnen etwas ausmachen, es auszuarbeiten? Bitte beschreiben Sie entweder die Methoden, über die Sie sprechen, oder zeigen Sie, wie Sie diese auf den Fall des OP anwenden. – YakovL

0

dieses Delegatmethode zur Klasse hinzufügen.

func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) { 
     if editingStyle == UITableViewCellEditingStyle.Delete { 
    } 
} 
Verwandte Themen