2016-01-22 47 views
0

我有這個按鈕是誰打電話在另一個視圖控制器(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) 
    } 
} 

My problem:

當我觸摸按鈕(moreButtonTapped)

行動表將不會出現。

非常感謝您

回答

1

你需要做的,如:

TimelineViewController().showActionSheetForPost(post!) 

或設置

weak var timeline: TimelineViewController() 
+0

當我改弱VAR,我得到這個錯誤:類「PostTableViewCell」沒有初始化。 – John

+0

與第一種溶液(TimelineViewController()showActionSheetForPost(崗位)。!)沒有工作 – John

+0

你設置爲'弱VAR時間表:TimelineViewController()'? – iamalizade

0

@iamalizade

我把所有錯誤的截圖在我TimelineViewController

The errors