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];