我有這個按鈕是誰打電話在另一個視圖控制器(TimelineViewController)的函數(showActionSheetForPost)。按鈕無效
My Button:
weak var timeline: TimelineViewController?
@IBAction func moreButtonTapped(sender: AnyObject) {
timeline?.showActionSheetForPost(post!)
}
The other 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)
}
}
當我觸摸按鈕(moreButtonTapped)My problem:
行動表將不會出現。
非常感謝您
當我改弱VAR,我得到這個錯誤:類「PostTableViewCell」沒有初始化。 – John
與第一種溶液(TimelineViewController()showActionSheetForPost(崗位)。!)沒有工作 – John
你設置爲'弱VAR時間表:TimelineViewController()'? – iamalizade