{"id":4238,"date":"2014-03-30T09:25:10","date_gmt":"2014-03-30T09:25:10","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/ios-who-is-file-owner-of-subview-collection-of-common-programming-errors\/"},"modified":"2014-03-30T09:25:10","modified_gmt":"2014-03-30T09:25:10","slug":"ios-who-is-file-owner-of-subview-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/ios-who-is-file-owner-of-subview-collection-of-common-programming-errors\/","title":{"rendered":"iOS who is file owner of subview?-Collection of common programming errors"},"content":{"rendered":"<p>I am newbie in iOS development and I have a problem to understand file owner logic.<\/p>\n<p>I have this situations:<\/p>\n<p>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&#8217;t matter if iPad or iPhone view is used). Let&#8217;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.<\/p>\n<p>If I understand, according to apple&#8217;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.<\/p>\n<p>But when I load subview with code:<\/p>\n<pre><code>     NSArray *nibContents = [[NSBundle mainBundle] loadNibNamed:@\"subview\" owner:self options:nil];\n<\/code><\/pre>\n<p>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.<\/p>\n<p>This error is shown then:<\/p>\n<blockquote>\n<p>Terminating app due to uncaught exception &#8216;NSUnknownKeyException&#8217;, reason: &#8216;[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key view.&#8217;<\/p>\n<\/blockquote>\n<p>How can I solve this? I tried to put as a owner @&#8221;subviewController&#8221; but it didn&#8217;t help. Thank you.<\/p>\n<p><strong>EDIT!!:<\/strong> So I was trying to solve this but still it doesn\u00b4t work. Here is a new situation:<\/p>\n<p>Subview controller is owner of the subview but custom class of the root view is a class (derived from UIView) which contains outlets.<\/p>\n<p>If I have in iPad\/iPhone controller owner:@&#8221;subviewController&#8221;, Igot this error:<\/p>\n<blockquote>\n<p>Terminating app due to uncaught exception &#8216;NSUnknownKeyException&#8217;, reason: &#8216;[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key view.&#8217;<\/p>\n<\/blockquote>\n<p>Where the view is a property from subview controller. Now tell me where is the problem. I am really desperate!<\/p>\n<p>Or If I have owner:self, some window with instructions is opened with EXC_BAD_ACCESS error.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4238","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4238","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4238"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4238\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4238"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4238"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4238"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}