Question

In my app I have this property (and its @synthesize in .m)

@property (nonatomic, strong) IBOutlet UILabel *titleHeader;

in a secondViewController.

The problem is that in iOS 7 if from firstViewController I do:

[secondViewController.titleHeader setText:@"title"];

it don't work, in iOS 6 it work.

why?

EDIT

I do it:

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];
Was it helpful?

Solution

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];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top