我有一个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]
}
非常感谢帮助。