ViewControllerB sets itself as the delegate in its viewDidLoad
method. This method is called as soon as the View Controller has loaded the view it manages (into its view
property). That view is loaded only when someone tries to access the view controller's view
property for the first time. See here. There's a good chance that ViewControllerB's view has not been loaded yet, so the viewDidLoad
method has not been called yet.
If you override the awakeFromNib
method like so:
(void) awakeFromNib {
[super awakeFromNib];
ViewControllerA *viewControllerA=[self.tabBarController.viewControllers
objectAtIndex:0];
viewControllerA.delegate = self;
}
it should work, since that method will be called when the view controller is initialized.