Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 自定义视图标签赢得';不变_Ios_Swift_Uicontainerview - Fatal编程技术网

Ios 自定义视图标签赢得';不变

Ios 自定义视图标签赢得';不变,ios,swift,uicontainerview,Ios,Swift,Uicontainerview,“我的视图”包含一个按钮,该按钮带来一个自定义视图,该视图包含一个ContainerView,并带有一个标签。当我将自定义视图置于前面时,标签文本为空。请问我的问题在哪里 视图控制器代码: @IBAction func PushAlert(sender: UIButton) { let alert = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("alertViewCon

“我的视图”包含一个按钮,该按钮带来一个自定义视图,该视图包含一个
ContainerView
,并带有一个标签。当我将自定义视图置于前面时,标签文本为空。请问我的问题在哪里

视图控制器代码:

@IBAction func PushAlert(sender: UIButton) {

    let alert = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("alertViewController") as! AlertViewController

    var alertText = AlertTextViewController()

    alertText.lblText = "DONE"

    alert.modalPresentationStyle = UIModalPresentationStyle.OverCurrentContext
    alert.modalTransitionStyle = UIModalTransitionStyle.CrossDissolve
    self.presentViewController(alert, animated: true, completion: nil)

}


我已经为源代码创建了一个链接,它将更容易理解

我认为您可能有一个事件顺序问题。尝试设置lblAlertText.text在viewwillshould而不是viewDidLoad中出现。

我认为您可能存在事件顺序问题。尝试在视图中设置lblAlertText.text将显示而不是viewDidLoad。

AlertTextViewController中设置var
lblText:String怎么样?

也许它被你的声明覆盖了(因为某种原因我无法解释)

或者等等,我被

var-alertText=AlertTextViewController()

在演示时,创建并演示ViewController
警报
alertText
alert
有什么关系

编辑:

class AlertViewController: UIViewController {

@IBOutlet weak var container: UIView!

override func viewDidLoad() {
    super.viewDidLoad()
    var alertText: AlertTextViewController = self.childViewControllers[0] as! AlertTextViewController
    alertText.lblAlertText.text = "Test"
    // Do any additional setup after loading the view.
}

在AlertViewController中执行此操作,它就会工作。我不知道你的最终目的是什么,这可能不是最优雅的解决方案。我已经创建了一个outlet,您的类的containerView。

在您的
AlertTextViewController中的var
lblText:String?

也许它被你的声明覆盖了(因为某种原因我无法解释)

或者等等,我被

var-alertText=AlertTextViewController()

在演示时,创建并演示ViewController
警报
alertText
alert
有什么关系

编辑:

class AlertViewController: UIViewController {

@IBOutlet weak var container: UIView!

override func viewDidLoad() {
    super.viewDidLoad()
    var alertText: AlertTextViewController = self.childViewControllers[0] as! AlertTextViewController
    alertText.lblAlertText.text = "Test"
    // Do any additional setup after loading the view.
}

在AlertViewController中执行此操作,它就会工作。我不知道你的最终目的是什么,这可能不是最优雅的解决方案。我已经创建了一个outlet,您的类的containerView。

在您放在这里的源代码中,空标签应该显示在哪里?应该显示在“警报视图”下脚本@brandonshegate中的文本您正在设置标签文本的
AlertTextViewController
AlertViewController
中包含的文本不同,它是您正在创建的新实例,并在方法结束时被销毁。您需要向
AlertViewController
添加一个方法,您可以将文本传递给该方法,并让该方法找到嵌入的
AlertTextViewController
并在其上设置标签文本。在您放在此处的源代码中,应该显示为空的标签的确切位置?应该显示在“警报视图”下脚本@brandonshegate中的文本您正在设置标签文本的
AlertTextViewController
AlertViewController
中包含的文本不同,它是您正在创建的新实例,并在方法结束时被销毁。您需要向
AlertViewController
添加一个方法,您可以将文本传递给该方法,并让该方法找到嵌入的
AlertTextViewController
并在其上设置标签文本。两者都在同一视图中,因此在我显示AlertViewController之前不应该调用AlertTextViewController吗?抱歉,我混淆了一些变量名称,我将看一看提供的源代码。我认为问题是在AlertViewController之前调用AlertTextViewController,因此它不会显示文本。我不知道如何解决它?嗯,我被容器视图和嵌入式segues弄糊涂了,因为我没有使用它,但我真的不明白你的警报和你的警报文本之间的联系。
alert
如何理解它将使用嵌入式segue来呈现您创建的
alertText
控制器?我希望我能知道这将解决我的问题:(两者都在同一视图中,所以在我呈现AlertViewController之前不应该调用AlertTextViewController吗?抱歉,我混淆了一些变量名称,我将查看提供的源代码。我认为问题是AlertTextViewController在AlertViewController之前被调用,因此它不会显示文本。我不知道如何解决它?嗯,我是c。)由容器视图和嵌入式segue融合,因为我没有使用它,但我真的无法理解您的警报和您的alertText之间的联系。
alert
如何理解它将使用嵌入式segue来显示您创建的
alertText
控制器?我希望我能知道解决我问题的方法:(