I am newbie in iOS development and I have a problem to understand file owner logic.
I have this situations:
I have two views (View_iPad, View_iPhone) and their controllers (ViewController_iPad, ViewController_iPhone). Based on a device where app is launched, particular view and its controller is used. Then, I add a subview from xib file to this view (it doesn't matter if iPad or iPhone view is used). Let's say that there is a different position of this subview in iPad and iPhone view. This subview contains some labels, so I have to create IBOulets in subviews controller.
If I understand, according to apple's logic, file owner of view is a controller (file which has access to this view and can communicate with it). So each of 3 views (iPhone, iPad, subview) has its own controller, it means that these controllers are file owners of these views.
But when I load subview with code:
NSArray *nibContents = [[NSBundle mainBundle] loadNibNamed:@"subview" owner:self options:nil];
and add it as a subview to iPad/iPhone view, there is a problem because this subview contains IBOutlets for labels and this labels are in subview controller and not in a iPhone/iPad controller.
This error is shown then:
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<__NSCFConstantString 0x7ab4> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key view.'
How can I solve this? I tried to put as a owner @"subviewController" but it didn't help. Thank you.
EDIT!!: So I was trying to solve this but still it doesn´t work. Here is a new situation:
Subview controller is owner of the subview but custom class of the root view is a class (derived from UIView) which contains outlets.
If I have in iPad/iPhone controller owner:@"subviewController", Igot this error:
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<__NSObject 0x715bf30> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key view.'
Where the view is a property from subview controller. Now tell me where is the problem. I am really desperate!
Or If I have owner:self, some window with instructions is opened with EXC_BAD_ACCESS error.