在我的应用程序中,我具有此属性(及其@synthesize
在.m中的属性)
@property (nonatomic, strong) IBOutlet UILabel *titleHeader;
在一个secondViewController
。
问题是,iOS 7
如果firstViewController
我这样做:
[secondViewController.titleHeader setText:@"title"];
它不起作用,iOS 6
它起作用了。
为什么?
编辑
我做到了:
SecondViewController *secondViewController = [[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil code:[object code]];
[self.navigationController pushViewController:secondViewController animated:YES];
[secondViewController.titleHeader setText:[object name]];
[secondViewController.headerView setBackgroundColor:colorHeaderGallery];
设置视图时secondViewController
尚未加载。您可以通过secondViewController.titleHeader
在将视图控制器推入导航堆栈后查询的值来验证这一点。
作为解决方法,您可以在 secondViewController
@property (nonatomic, strong) NSString *titleHeaderText;
然后设置该属性,而不是secondViewController.titleHeader setText
例如
secondViewController.titleHeaderText = [object name];
之后,您可以使用secondViewController
的viewDidLoad
方法来设置标签的文本。
[self.titleHeader setText:self.titleHeaderText ];
编辑:
的行为pushViewController
似乎已在iOS 7中更改。我尝试过并复制了您的问题。
如果您不希望进行上述更改,则一种变通方法是访问的视图secondViewController
,以便在调用之前加载其视图label setText
。
例如
SecondViewController *secondViewController = [[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil code:[object code]];
[self.navigationController pushViewController:secondViewController animated:YES];
[secondViewController view];
[secondViewController.titleHeader setText:[object name]];
[secondViewController.headerView setBackgroundColor:colorHeaderGallery];
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句