对于UICollectionView,Swift /是否有任何等效的UITableViewRowAction?

时间:2016-03-02 22:29:24

标签: ios swift

我有一个UICollectionView,单元格中有一个按钮。我希望用户共享CollectionViewCell内的UIImage图像。

在片刻我有这段代码:

class EventsCollectionViewCell: UICollectionViewCell {

@IBOutlet weak var eventsImageView: UIImageView!

@IBAction func cellDetailButton(sender: AnyObject) {
    var alertView:UIAlertView = UIAlertView()
    alertView.title = "Alert!"
    alertView.message = "Message"
    alertView.delegate = self
    alertView.addButtonWithTitle("OK")
    alertView.show()

}

我在另一个项目中使用此代码作为tableView,但我不知道如何在CollectionViewCell中使用它:

    override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {

    let shareRaceAction = UITableViewRowAction(style: .Default, title: "Share") {
        (action: UITableViewRowAction, indexPath: NSIndexPath) -> Void in

        let sheet = UIAlertController(title: nil, message: "Teilen mit", preferredStyle: .ActionSheet)
        let race = self.races[indexPath.row]

        //
        let twAction = self.newAction(SLServiceTypeTwitter, race: race)
        sheet.addAction(twAction)

        //
        let fbAction = self.newAction(SLServiceTypeFacebook, race: race)
        sheet.addAction(fbAction)

        //
        let cancelAction = UIAlertAction(title: "Abbrechen", style: .Cancel, handler: nil)
        sheet.addAction(cancelAction)

        self.presentViewController(sheet, animated: true, completion: nil)
    }

    shareRaceAction.backgroundColor = UIColor.blueColor()

    return [shareRaceAction]
}

非常感谢帮助。

0 个答案:

没有答案