1

在我的应用程序中,我有这个属性(及其@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];
4

1 回答 1

3

The views of secondViewController have not been loaded yet when you set them. You can verify this by querying for the value of secondViewController.titleHeader after pushing the view controller to the navigation stack.

As a fix, you can declare a property in secondViewController

@property (nonatomic, strong) NSString *titleHeaderText;

then set that property instead of secondViewController.titleHeader setText
e.g.

secondViewController.titleHeaderText = [object name];

After that, in your secondViewController's viewDidLoad method, you can set the text of your label.

[self.titleHeader setText:self.titleHeaderText ];

EDIT:
The behavior of pushViewController seems to have changed in iOS 7. I have tried and replicated your issue.

If you do not want the above change, a workaround is by accessing the view of secondViewController, so that its views will be loaded before you call label setText.
e.g.

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];
于 2013-10-01T09:22:51.213 回答