2017-06-05 20 views
0

我使用的PopupDialog庫,並有一個按鈕,拍了拍負載時的彈出如下圖所示的代碼:如何打開視圖控制器時,彈出是開放的 - 迅速3

// Create the dialog 
let popup_around_me = AroundMePopUpViewController(nibName: "popup_around_me", bundle: nil) 
popup_around_me.gh = self.getJobByLatitude(latitude: marker.position.latitude) 
let popup = PopupDialog(viewController: popup_around_me, buttonAlignment: .horizontal, transitionStyle: .bounceDown, gestureDismissal: true) 

present(popup, animated: true, completion: nil) 
//print("marker.position.latitude: \(marker.position.latitude)") 

在我的彈出有是兩個打開控制器的按鈕。

因爲我使用導航欄,我想我應該先關閉彈出窗口然後打開我的控制器。不這樣做我的導航欄不加載。

但我不知道這是否是正確的做法。 如果沒關係,我該怎麼辦(關閉彈出窗口並打開控制器)?

我的按鈕功能:

func cliclOnContent(tapGestureRecognizer: UITapGestureRecognizer) 
    { 
     print("job id: \(self.gh.id)") 

//below codes not load my navigation. 
//  let vc = self.storyboard!.instantiateViewController(withIdentifier: "ContentAJobViewController") as! ContentAJobViewController 
//  vc.job_id = self.gh.id 
//  self.navigationController?.pushViewController(vc, animated: true) 

     // let storyboard = UIStoryboard(name: "Main", bundle: nil) 
//  let controller = storyboard?.instantiateViewController(withIdentifier: "ContentAJobViewController") as! ContentAJobViewController 
//  controller.job_id = self.gh.id 
//  self.present(controller, animated: true, completion: nil) 

    } 
+0

你能提供一個參考(鏈接)到你正在使用的'PopupDialog'嗎? –

+0

https://github.com/Orderella/PopupDialog –

+0

你可以嘗試使用'popup.tapButtonWithIndex'來關閉你的彈出窗口嗎? –

回答

0

編輯:

其實你不必關閉它。它會自動關閉所有你需要做的就是在相應的按鈕操作中調用你的視圖控制器。

我有一個視圖控制器,我用取消按鈕中的segue這樣做了一個調用。

enter image description here

而且我的輸出是一樣this.by我只是用他們的演示文件進行快速反應的方式。

enter image description here

+0

如何關閉彈出窗口?如何檢測彈出窗口是否關閉?有沒有任何功能來檢測它? –

0

我不熟悉以上的生命週期中提到PopupDialog,但如果它的工作方式類似於UIAlertController當按鈕動作都完成它會自動解散。

看起來您正在使用自定義PopupDialog版本。你應該實現你類似這樣的按鈕和按鍵操作:

func showCustomDialog(animated: Bool = true) { 

     // Create a custom view controller 
     let popup_around_me = AroundMePopUpViewController(nibName: "popup_around_me", bundle: nil) 


     let popup_around_me = AroundMePopUpViewController(nibName: "popup_around_me", bundle: nil) 
     popup_around_me.gh = self.getJobByLatitude(latitude: marker.position.latitude) 
     // Create the dialog 
     let popup = PopupDialog(viewController: popup_around_me, buttonAlignment: .horizontal, transitionStyle: .bounceDown, gestureDismissal: true) 


     // Create first button 
     let buttonOne = CancelButton(title: "CANCEL", height: 60) { 
      // Do what you want when you cancel 
     } 

     // Create second button 
     let buttonTwo = DefaultButton(title: "Open VC", height: 60) { 
      self.gotoMyOtherViewController() 
     } 

     // Add buttons to dialog 
     popup.addButtons([buttonOne, buttonTwo]) 

     // Present dialog 
     present(popup, animated: true, completion: nil) 
    } 
} 

通知「打開VC」按鈕動作此範圍內調用self.gotoMyOtherViewController()是你會因爲你是在segue代替使用navigation bar打開其他VC

func gotoMyOtherViewController(){ 
    let vc = self.storyboard!.instantiateViewController(withIdentifier: "ContentAJobViewController") as! ContentAJobViewController 
    vc.job_id = self.gh.id   
    navigationController?.pushViewController(vc, animated: true) 
} 
相關問題