editActionsForRowAtIndexPath 未在 iOS 8 和 Xcode 7 上执行
editActionsForRowAtIndexPath not executing on iOS 8 with Xcode 7
我正在 3 台设备上测试我的应用程序。 iOS 9 上有 2 台设备,iOS 8 上有一台设备。在 iOS 9 上,功能 editActionsForRowAtIndexPath
正在运行,当我滑动一个单元格时会显示操作。但是在 iOS 8 上,我无法滑动单元格。
这是我的代码:
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]
}
当然我添加了
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
}
可能是 Xcode 错误?
有什么想法吗?
谢谢!
Under iOS 8 editActions 仅当在您的委托中实现 commitEditingStyle 调用时才启用。在您的 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
}
如果您有自定义 UITableViewCell
,并且有 GestureRecognizer
,请检查委托方法 - shouldRecognizeSimultaneouslyWithGestureRecognizer:
将此委托方法添加到 class。
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if editingStyle == UITableViewCellEditingStyle.Delete {
}
}
我正在 3 台设备上测试我的应用程序。 iOS 9 上有 2 台设备,iOS 8 上有一台设备。在 iOS 9 上,功能 editActionsForRowAtIndexPath
正在运行,当我滑动一个单元格时会显示操作。但是在 iOS 8 上,我无法滑动单元格。
这是我的代码:
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]
}
当然我添加了
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
}
可能是 Xcode 错误? 有什么想法吗?
谢谢!
Under iOS 8 editActions 仅当在您的委托中实现 commitEditingStyle 调用时才启用。在您的 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
}
如果您有自定义 UITableViewCell
,并且有 GestureRecognizer
,请检查委托方法 - shouldRecognizeSimultaneouslyWithGestureRecognizer:
将此委托方法添加到 class。
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if editingStyle == UITableViewCellEditingStyle.Delete {
}
}