【发布时间】:2015-07-20 13:34:29
【问题描述】:
我的视图包含一个按钮,它带来一个自定义视图,其中包含一个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)
}
class AlertTextViewController: UIViewController {
@IBOutlet weak var lblAlertText: UILabel!
var lblText = ""
override func viewDidLoad() {
super.viewDidLoad()
lblAlertText.text = lblText
}
}
我已经为源代码创建了一个链接,这将更容易理解source code
【问题讨论】:
-
在你放在这里的源代码中,应该在哪里显示空白的标签?
-
它应该显示在故事板@BrandonShega 中的“警报视图”文本下
-
您设置标签文本的
AlertTextViewController与您的AlertViewController中包含的不同,它是您正在创建的一个新实例,它会在方法结束。您需要向AlertViewController添加一个可以向其传递文本的方法,并让该方法找到嵌入的AlertTextViewController并在其上设置标签文本。
标签: ios swift uicontainerview