2016-04-02 5 views
0

プログラムでビューをポップしようとしていますが、問題が発生しています。プログラムでオフにポップビュー

import UIKit 

class CreatePostViewController: UIViewController { 

    var isAnimating: Bool = false 
    var dropDownViewIsDisplayed: Bool = false 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     createDescriptionField() 
     createLabels() 
     createInputFields() 
     createBackButton() 

    } 
    //More code omitted 

    func createBackButton(){ 
     let button = UIButton() 
     button.setTitle("back", forState: .Normal) 
     button.setTitleColor(UIColor.blueColor(), forState: .Normal) 
     button.frame = CGRectMake(200,200,100,50) 
     button.backgroundColor = UIColor.redColor() 
     button.addTarget(self, action: "goBack:", forControlEvents: .TouchUpInside) 
     self.view.addSubview(button) 

    } 

    func goBack(sender: UIButton){ 
     navigationController?.popToRootViewControllerAnimated(true) 

    } 

} 

私はこのような別のクラスからこのクラスを追加:私はちょうどラインでCreatePostViewControllerポップ示唆した他の多くの記事読ま

import UIKit 

class HomeViewController: UIViewController { 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     needCashButton() 
    } 

    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
     // Dispose of any resources that can be recreated. 
    } 

    func needCashButton(){ 

     let image = UIImage(named: "GlossyRoundedButton.png") as UIImage? 
     let button = UIButton() 
     button.setTitle("Do Job", forState: .Normal) 
     button.setTitleColor(UIColor.blueColor(), forState: .Normal) 
     button.setBackgroundImage(image, forState: .Normal) 
     button.frame = CGRectMake(225,200,100,50) 

     button.addTarget(self, action: "cashButtonPressed:", forControlEvents: .TouchUpInside) 
     self.view.addSubview(button) 

    } 


    func cashButtonPressed(sender: UIButton){ 
     let findJob = CreatePostViewController() 
     self.presentViewController(findJob, animated: false, completion: nil) 
    } 

} 

navigationController?.popToRootViewControllerAnimated(true)をしかし、それは時に何もしません。私はボタンをクリックします。私はここで見落としているものがありますか?

答えて

1

のようなものを使用することをお勧めそれをUINavigationViewControllerの中で閉じます。

self.navigationController.popViewControllerAnimated(true) 
+0

これはあなたに感謝しました – Anderology

0

navigationControllerは、実際にナビゲーションコントローラ:)を使用している場合にのみ機能します。

self.dismissViewControllerAnimated(true, completion: nil) 

お持ちの場合:だから私はそれを却下するためにこれを使用し、あなたのUIViewControllerはUINavigationViewControllerでませである(またはそれがモーダルモードで表示された)場合には、この

let vc = UINavigationController(rootViewController: CreatePostViewController()) 
self.presentViewController(vc, animated: false, completion: nil) 
関連する問題