加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-14 05:36:51 所属栏目:百科 来源:网络整理
导读:我在3台设备上测试我的应用程序. iOS 9上的2个设备和iOS 8上的一个设备.在iOS 9上,当我滑动一个单元格时,editActionsForRowAtIndexPath的功能正在运行,并且显示动作.但是在iOS 8中,我无法滑动单元格. 这是我的代码: func tableView(tableView: UITableView,
我在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",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,completion: nil)
        } else {
            AllArticle[indexPath.row].Favoris = true
            let alreadyInView = UIAlertController(title: "Favori ajouté",message: "Cet article fait maintenant parti de vos favoris",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错误?
有任何想法吗 ?

谢谢 !

在iOS 8下,只有在委托中实现了commitEditingStyle调用时,才能启用editActions.在tableViewController中添加bellow方法:
- (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
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读