Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS Controllers for universal (iPhone/iPad) app
    text
    copied!<p>I am just working on iOS app and I want to make it universal for both iPhones and iPads. This is done and works without any problems:</p> <pre><code>if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { self.viewController_iPhone = [[ViewController_iPhone alloc] initWithNibName:@"ViewController_iPhone" bundle:nil]; } else { self.viewController_iPad = [[ViewController_iPad alloc] initWithNibName:@"ViewController_iPad" bundle:nil]; } if (self.viewController_iPhone == nil) self.window.rootViewController = self.viewController_iPad; else self.window.rootViewController = self.viewController_iPhone; </code></pre> <p>There is a view for each controller (ViewController_iPad.xib, ViewController_iPhone.xib). It doesn't matter which view is loaded in my problem. In a view there is a subview added (UIScrolView). And in this ScrollView there are two views from xib:</p> <pre><code>NSArray *nibContents = [[NSBundle mainBundle] loadNibNamed:@"SubView1" owner:self options:nil]; UIView *view = [nibContents objectAtIndex:0]; view.frame = CGRectMake(2, 0, scrollView.frame.size.width - 2, scrollView.frame.size.height); [scrollView addSubview:view]; nibContents = [[NSBundle mainBundle] loadNibNamed:@"SubView2" owner:self options:nil]; view = [nibContents objectAtIndex:0]; view.frame = CGRectMake(scrollView.frame.size.width + 2 , 0, scrollView.frame.size.width - 4, scrollView.frame.size.height); [scrollView addSubview:view]; </code></pre> <p>(This code is in iPad/iPhone controller). Still everything is OK. But I don't know how to set owners (in IB) of these subviews that are shown in ScrollView. These subviews are in ScrollView which is in a main view so I want to set owners of these subviews as iPad/iPhone controller. But as a owner can be only one class. Can you tell me how to set owners if I have two main controllers and I don't know which one will be loaded in runtime. Thank you.</p> <p>EDIT: I have another question: I have ViewController_iPhone. It has a View property and this property is assigned to the "root" view in the main view in ViewController_iPhone (.xib). Can I assign this view property also to subview view? Because I got EXC_BAD_ACCESS error if I assign view property of ViewController_iPhone to a "root" view of subview in IB. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload