自定义视图中的标签未更新

时间:2016-01-07 16:52:16

标签: ios

我在xib中使用类InfoPopUpView创建了一个自定义UIView。我将它添加到我的viewController。它运行良好,自定义类xib在文件所有者中设置。 我可以在我的第一个viewcontroller中设置titleLbl变量没问题。

当我在另一个viewcontroller中想要再次使用InfoPopUpView但具有不同的标题时出现我的问题... 标题不会更改/更新。就好像InfoPopUpView会记住我设置的最后一个标题而不关心更改它。

我如何初始化? InfoPopUpView类中的titleLbl变量,以便我以后可以更改它?

非常感谢任何帮助 - 谢谢!

  

的ViewController

var popUpView: InfoPopUpView!
popUpView = InfoPopUpView(frame: CGRectMake(0, 0, 300, 268))
popUpView.titleLbl.text = "MyFirstTitle"
view.addSubview(popUpView)
  

自定义类

class InfoPopUpView: UIView {

    var view: UIView!

    @IBOutlet weak var okBtn: UIButton!
    @IBOutlet weak var titleLbl: UILabel!
    @IBOutlet weak var textView: UITextView!

    @IBAction func didTapOkBtn(sender: AnyObject) {
        NSNotificationCenter.defaultCenter().postNotificationName("popUpController", object: nil)
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        setup()
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        setup()
    }


    func setup() {
        view = loadViewFromNib()
        view.frame = bounds
        view.autoresizingMask = [UIViewAutoresizing.FlexibleWidth, UIViewAutoresizing.FlexibleHeight]
        addSubview(view)

    }

    func loadViewFromNib() -> UIView {
        let bundle = NSBundle(forClass: self.dynamicType)
        let nib = UINib(nibName: "InfoPopUpView", bundle: bundle)
        let view = nib.instantiateWithOwner(self, options: nil)[0] as! UIView

        return view
    }
}

0 个答案:

没有答案