iOS:在iOS7中设置属性

骑自行车更好

在我的应用程序中,我具有此属性(及其@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];
Dj S

设置视图时secondViewController尚未加载。您可以通过secondViewController.titleHeader在将视图控制器推入导航堆栈后查询的值来验证这一点

作为解决方法,您可以在 secondViewController

@property (nonatomic, strong) NSString *titleHeaderText;

然后设置该属性,而不是secondViewController.titleHeader setText
例如

secondViewController.titleHeaderText = [object name];

之后,您可以使用secondViewControllerviewDidLoad方法来设置标签的文本。

[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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章