我有这个按钮,他在另一个ViewController(TimelineViewController)中调用一个函数(showActionSheetForPost)。
我的按钮:
weak var timeline: TimelineViewController?
@IBAction func moreButtonTapped(sender: AnyObject) {
timeline?.showActionSheetForPost(post!)
}
另一个ViewController(TimelineViewController):
class TimelineViewController: UIViewController, TimelineComponentTarget {
@IBOutlet weak var tableView: UITableView!
// MARK: UIActionSheets
func showActionSheetForPost(post: Post) {
if (post.user == PFUser.currentUser()) {
showDeleteActionSheetForPost(post)
} else {
showFlagActionSheetForPost(post)
}
}
func showDeleteActionSheetForPost(post: Post) {
let alertController = UIAlertController(title: nil, message: "Do you want to delete this post?", preferredStyle: .ActionSheet)
let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil)
alertController.addAction(cancelAction)
let destroyAction = UIAlertAction(title: "Delete", style: .Destructive) { (action) in
post.deleteInBackgroundWithBlock({ (success: Bool, error: NSError?) -> Void in
if (success) {
self.timelineComponent.removeObject(post)
} else {
// restore old state
self.timelineComponent.refresh(self)
}
})
}
alertController.addAction(destroyAction)
self.presentViewController(alertController, animated: true, completion: nil)
}
func showFlagActionSheetForPost(post: Post) {
let alertController = UIAlertController(title: nil, message: "Do you want to flag this post?", preferredStyle: .ActionSheet)
let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil)
alertController.addAction(cancelAction)
let destroyAction = UIAlertAction(title: "Flag", style: .Destructive) { (action) in
post.flagPost(PFUser.currentUser()!)
}
alertController.addAction(destroyAction)
self.presentViewController(alertController, animated: true, completion: nil)
}
}
我的问题:
当我触摸Button(moreButtonTapped)时,操作表不会出现。
非常感谢
答案 0 :(得分:1)
您需要这样做:
TimelineViewController().showActionSheetForPost(post!)
或设置
weak var timeline: TimelineViewController()
答案 1 :(得分:0)