xcode - Change UILabel from appDelegate -
i want stuff appdelegate in xcode. 1 of these things change uilabel.
viewcontroller *viewcontroller = [[uistoryboard storyboardwithname:@"main_iphone" bundle:nil] instantiateviewcontrollerwithidentifier:@"id"]; viewcontroller.label.text = @"heeej";
i told trick. doesn't work. label doesn't change. know problem is?
there several problems:
- don't in appdelegate except loading window initial view controllers (if needed).
- you instantiating new view controller in first line. assume have view controller , want change label in view controller. need reference view controller , use reference send messages it.
- the label should not property of view controller. should try follow design pattern model-view-controller or pattern model-view-viewmodel. ask preferred search engine if don't know.
id
identifier in objective-c bad idea because used object type.
edit: don't need reference change property in view controller. use notifications update label. system sends notification name uiapplicationwillenterforgroundnotification' (see [here][1]). add view controller observer the
[nsnotificationcenter defaultcenter]` name , react on notification. read apple documentation if don't know talking about.
Comments
Post a Comment