Note that there are some explanatory texts on larger screens.

plurals
  1. POviewController.view.superview is nil
    primarykey
    data
    text
    <p>I'm trying to implement a page-scroll functionality in my project. I develop for iOS 5, with storyboards (and ARC). This is what I did in my storyboard :</p> <p><img src="https://i.stack.imgur.com/T7CGm.png" alt="enter image description here"></p> <p>The first viewController (on the left) has a scrollView and a pageControl. Its class is called <code>GlobalDashboardViewController</code>, and inherits from the class <code>DashboardViewController</code> (which inherits from <code>UIViewController</code>). The other 2 controllers are simple UIViewControllers with identifiers (<em>MainDashboard</em> and <em>SecondaryDashboard</em>).</p> <p>In <code>GlobalDashboardViewController.m</code>, there is only a viewDidLoad, which gets the childViewControllers :</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; [self addChildViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"MainDashboard"]]; [self addChildViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"SecondaryDashboard"]]; } </code></pre> <p><code>DashboardViewController.m</code> is a bit more complex. Here are the most important methods :</p> <pre><code>- (void)viewDidLoad { // Calling the viewDidLoad above to populate the childViewControllers array [super viewDidLoad]; [self.scrollView setPagingEnabled:YES]; [self.scrollView setScrollEnabled:YES]; [self.scrollView setShowsHorizontalScrollIndicator:NO]; [self.scrollView setShowsVerticalScrollIndicator:NO]; [self.scrollView setDelegate:self]; } -(void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; self.pageControl.currentPage = 0; _page = 0; [self.pageControl setNumberOfPages:[self.childViewControllers count]]; UIViewController *viewController = [self.childViewControllers objectAtIndex:self.pageControl.currentPage]; if (viewController.view.superview != nil) { [viewController viewWillAppear:animated]; } self.scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * [self.childViewControllers count], scrollView.frame.size.height); } </code></pre> <p>There are plenty of other methods, but I don't think they're relevant, because here is my problem: the app launches, and I see the scrollView and the pageControl. The background is dark gray, as I set it in the <em>GlobalDashboard</em> viewController. I can scroll correctly, and the pageControl is updated. But I don't see the other views. When I place a breakpoint at the <em>if</em> in <code>viewWillAppear</code>, and look at <code>viewController</code>, it's named correctly (<code>Dashboard Page 1</code>, which is the name I gave to the controller in the storyboard), but its <code>_view</code> property shows <em>0x00000000</em>, as you can see here :</p> <p><img src="https://i.stack.imgur.com/E0d3W.png" alt="enter image description here"></p> <p>So, I never get inside the <em>if</em>, which is where some of the magic of actually showing the viewControllers happens...</p> <p>My work is based on an example project you can find here : <a href="https://github.com/wannabegeek/PageViewController" rel="nofollow noreferrer">PageViewController</a>. When I run it, it works perfectly. I have no clue why I can't make it work in my own project.</p> <p>Any ideas ?</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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