{"id":4711,"date":"2014-03-30T14:50:00","date_gmt":"2014-03-30T14:50:00","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/how-to-assign-managedobjectcontext-to-a-dynamic-viewcontroller-collection-of-common-programming-errors\/"},"modified":"2014-03-30T14:50:00","modified_gmt":"2014-03-30T14:50:00","slug":"how-to-assign-managedobjectcontext-to-a-dynamic-viewcontroller-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/how-to-assign-managedobjectcontext-to-a-dynamic-viewcontroller-collection-of-common-programming-errors\/","title":{"rendered":"How to assign managedObjectContext to a dynamic viewController?-Collection of common programming errors"},"content":{"rendered":"<p>I have 4 buttons on main screen, each one sends me to a viewController. The third one, sends me to a view on which I wanna set the managedObjectContext. If I use the class name to create an instance, it&#8217;s all right. But I&#8217;m looking for a way to use just one method that uses an array to retrieve the name of the Class for the needed viewController. But it&#8217;s leading to an error message, like it doesn&#8217;t exist on the destination viewController??? Anyone have any ideas about this aproach??? Thanks in advance!<\/p>\n<p>Here is the code:<\/p>\n<pre><code>NSArray *viewControllers = [[NSArray alloc]\ninitWithObjects:@\"nil\",@\"OpcoesView\",@\"nil\",@\"TheNames\", nil];\n\nNSString *viewName = [viewControllers objectAtIndex:[sender tag]]; \/\/the taped button tag\n\nUIViewController *viewController = [[NSClassFromString(viewName) alloc]\ninitWithNibName:viewName bundle:nil];\n\n\nif ([sender tag] == 3) {\n    viewController.managedObjectContext = contexto;\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I have 4 buttons on main screen, each one sends me to a viewController. The third one, sends me to a view on which I wanna set the managedObjectContext. If I use the class name to create an instance, it&#8217;s all right. But I&#8217;m looking for a way to use just one method that uses [&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-4711","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4711","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=4711"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4711\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4711"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4711"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4711"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}