title: Create a UIPageViewController with a UITableView in each page
body: <p>I have been reading things on stack overflow for quite a while now but this is my first post, only because it is the first time I have a problem that no one else seems to have fixed yet!</p>
  
  <p>Ok, down to business. It should be a simple matter to put UITableViews inside a UIPageView but I am having difficulties. I have a ViewController and contentViewController. I am using .xibs instead of storyboarding. The contentViewController.xib is a Table View and the ViewController.xib is a View. I am only focusing on iPhone. The UITableView is connected to dataSource, delegate, and Referencing Outlet named theTableView.</p>
  
  <p>The project builds but when I run it I get the following error message:</p>
  
  <pre><code>    2013-03-17 16:14:23.026 pageApp[775:c07] *** Assertion failure in -[UITableView layoutSublayersOfLayer:], /SourceCache/UIKit_Sim/UIKit-2380.17/UIView.m:5776
      2013-03-17 16:14:23.028 pageApp[775:c07] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Auto Layout still required after executing -layoutSubviews. UITableView's implementation of -layoutSubviews needs to call super.'
      *** First throw call stack:
      (0x1c93012 0x10d0e7e 0x1c92e78 0xb66665 0x6539f 0x10e46b0 0x228ffc0 0x228433c 0x228feaf 0x1042bd 0x4cb56 0x4b66f 0x4b589 0x4a7e4 0x4a61e 0x4b3d9 0x4e2d2 0xf899c 0x45574 0x4576f 0x45905 0x4e917 0x20eb 0x12157 0x12747 0x1394b 0x24cb5 0x25beb 0x17698 0x1beedf9 0x1beead0 0x1c08bf5 0x1c08962 0x1c39bb6 0x1c38f44 0x1c38e1b 0x1317a 0x14ffc 0x1d2d 0x1c55)
      libc++abi.dylib: terminate called throwing an exception
  </code></pre>
  
  <p>This crashes after -(void)viewDidLoad{} in ViewController.m and I have not yet learned how to fix auto layout/ layoutSubview errors. Does anyone else know how?</p>
  
  <p>I have limited experience with ios development so I am sure that I just don't have the right pieces in the right spots. I used <a href="http://www.techotopia.com/index.php/An_Example_iOS_5_iPhone_UIPageViewController_Application" rel="nofollow">http://www.techotopia.com/index.php/An_Example_iOS_5_iPhone_UIPageViewController_Application</a> to get this far. </p>
  
  <p>My code is as follows:</p>
  
  <p>ViewController.h</p>
  
  <pre><code>    #import &lt;UIKit/UIKit.h&gt;
      #import "contentViewController.h"
  
      @interface ViewController : UIViewController
      &lt;UIPageViewControllerDataSource&gt;
      {
          UIPageViewController *pageController;
          NSArray *pageContent;
      }
      @property (strong, nonatomic) UIPageViewController *pageController;
      @property (strong, nonatomic) NSArray *pageContent;
      @end
  </code></pre>
  
  <p>ViewController.m</p>
  
  <pre><code>    #import "ViewController.h"
  
      @interface ViewController ()
  
      @end
  
      @implementation ViewController
      @synthesize pageController, pageContent;
  
      - (contentViewController *)viewControllerAtIndex:(NSUInteger)index
      {
          // Return the data view controller for the given index.
          if (([self.pageContent count] == 0) || (index &gt;= [self.pageContent count])) {
              return nil;
          }
  
          // Create a new view controller and pass suitable data.
          contentViewController *dataViewController =[[contentViewController alloc]initWithNibName:@"contentViewController"bundle:nil];
          dataViewController.dataObject =[self.pageContent objectAtIndex:index];
          return dataViewController;
      }
  
      - (NSUInteger)indexOfViewController:(contentViewController *)viewController
      {
          return [self.pageContent indexOfObject:viewController.dataObject];
      }
  
      - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
      {
          NSUInteger index = [self indexOfViewController:(contentViewController *)viewController];
          if ((index == 0) || (index == NSNotFound)) {
              return nil;
          }
  
          index--;
          return [self viewControllerAtIndex:index];
      }        
  
      - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
      {
          NSUInteger index = [self indexOfViewController:(contentViewController *)viewController];
          if (index == NSNotFound) {
              return nil;
          }
  
          index++;
          if (index == [self.pageContent count]) {
              return nil;
          }
          return [self viewControllerAtIndex:index];
      }
  
      - (void) createContentPages
      {
          NSMutableArray *pageStrings = [[NSMutableArray alloc] init];
          for (int i = 1; i &lt; 4; i++)
          {        
              NSString *contentString = [[NSString alloc]initWithFormat:@"Chapter %d \nThis is the page %d of content displayed using UIPageViewController in iOS 5.", i, i];
              [pageStrings addObject:contentString];
          }
          pageContent = [[NSArray alloc] initWithArray:pageStrings];
      }
  
      - (void)viewDidLoad
      {
          [super viewDidLoad];
          [self createContentPages];
  
          self.pageController = [[UIPageViewController alloc]initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
  
          pageController.dataSource = self;
          [[pageController view] setFrame:[[self view] bounds]];
  
          contentViewController *initialViewController = [self viewControllerAtIndex:0];
          NSArray *viewControllers = [NSArray arrayWithObject:initialViewController];
  
          [pageController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
  
          [self addChildViewController:pageController];
          [[self view] addSubview:[pageController view]];
          [pageController didMoveToParentViewController:self];
      }
  
      - (void)didReceiveMemoryWarning
      {
          [super didReceiveMemoryWarning];
          // Dispose of any resources that can be recreated.
      }
  
      @end
  </code></pre>
  
  <p>contentViewController.h</p>
  
  <pre><code>    #import &lt;UIKit/UIKit.h&gt;
  
      @interface contentViewController : UIViewController
      @property (strong, nonatomic) IBOutlet UITableView *theTableView;
      @property (strong, nonatomic) id dataObject;
      @property (strong, nonatomic) NSArray *pageContent;
      @end
  </code></pre>
  
  <p>contentViewController.m</p>
  
  <pre><code>    #import "contentViewController.h"
  
      @interface contentViewController ()
  
      @end
  
      @implementation contentViewController
      @synthesize theTableView, dataObject, pageContent;
  
      - (void)viewWillAppear:(BOOL)animated
      {
          [super viewWillAppear:animated];
      }
      - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
      {
          self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
          if (self) {
              // Custom initialization
          }
          return self;
      }
  
      - (void) createContentPages
      {
          NSMutableArray *pageStrings = [[NSMutableArray alloc] init];
          for (int i = 1; i &lt; 4; i++)
          {
              NSString *contentString = [[NSString alloc]initWithFormat:@"Chapter %d \nThis is the page %d of content displayed using UIPageViewController in iOS 5.", i, i];
              [pageStrings addObject:contentString];
          }
          pageContent = [[NSArray alloc] initWithArray:pageStrings];
      }
  
      - (void)viewDidLoad
      {
          [super viewDidLoad];
          [self createContentPages];
      }
  
      - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection (NSInteger)section
      {
          return 4;
      }
  
      - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath (NSIndexPath *)indexPath
      {
          static NSString *simpleTableIdentifier = @"SimpleTableItem";
  
          UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
  
          if (cell == nil) {
              cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
          }
  
          cell.textLabel.text = [pageContent objectAtIndex:indexPath.row];
          return cell;
      }
  
      - (void)didReceiveMemoryWarning
      {
          [super didReceiveMemoryWarning];
          // Dispose of any resources that can be recreated.
      }
  
      @end
  </code></pre>
  
  <p>So if anyone could straighten me out I would appreciate it.</p>