gpt4 book ai didi

ios - 以编程方式关闭弹出 View

转载 作者:行者123 更新时间:2023-11-29 01:05:51 25 4
gpt4 key购买 nike

我正尝试以编程方式弹出 View ,但遇到了问题。

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)

}

}

我从这样的另一个类添加这个类:

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)
}

}

我阅读了许多其他帖子,建议我只使用以下行弹出 CreatePostViewController:navigationController?.popToRootViewControllerAnimated(true) 但是当我单击按钮时它没有执行任何操作。我在这里忽略了什么吗?

最佳答案

如果您的 UIViewController NOT 在 UINavigationViewController 中(或者它以模态方式呈现),请使用它来关闭它:

self.dismissViewControllerAnimated(true, completion: nil)

如果你在 UINavigationViewController 中有它,使用这个关闭它:

self.navigationController.popViewControllerAnimated(true)

关于ios - 以编程方式关闭弹出 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36379758/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com