Author Topic: Container Views  (Read 5671 times)

runartrollet

  • Newbie
  • *
  • Posts: 15
  • The creator of Tally Board
    • View Profile
    • Tally Board
Container Views
« on: April 02, 2014, 08:09:53 AM »
Hi, I am trying to build an iPad game. Right now I am just trying to get a grip of everything in Xcode. I am thinking of having navigational buttons around the edge of the screen, with a separate container view which changes depending on which button the player presses around the edge of the screen. This container can hold different items, like images, buttons and tables. At this point I am trying to have just a table view, populated dynamlicly. However, I don't quite understand how to call the tableview inside the container, and if I should give the container its own UIViewController -class. I've tried searching the new for this, but I wan unable to find what I was looking for.

In short I want to:
Populate a table view inside a container.

Any help would be appreciated.
http://TallyBoardApp.com

- A game of Logic, Strategy and Math.

kjmcneish

  • Administrator
  • *****
  • Posts: 719
    • View Profile
Re: Container Views
« Reply #1 on: April 03, 2014, 04:40:34 PM »
Great question. The information you're looking for is detailed in this iOS Developer Library article:

https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/CreatingCustomContainerViewControllers/CreatingCustomContainerViewControllers.html

It shows you how to dynamically add and remove view controllers and content from the container at run time.

All the best!
Kevin

runartrollet

  • Newbie
  • *
  • Posts: 15
  • The creator of Tally Board
    • View Profile
    • Tally Board
Re: Container Views
« Reply #2 on: April 08, 2014, 01:42:43 AM »
Ok, great. Got it working somewhat here. I am however stumped here, with performing segues on the container view. I do manage to do it from the MainView. I added a public method for it like this:

Code: [Select]
- (void)changeView:(NSString *)where
{
    NSLog(@"Going to %@", where);
    NSLog(@"Going from %@",self.childViewControllers);
   
    UINavigationController *a = self.childViewControllers[0];
    UINavigationController *b = a.childViewControllers[0];
   
    [b performSegueWithIdentifier:where sender:self];
   
}

This code is in the MainView.m -file. I called this from a button which is in the MainView, and it works. However, I tried calling it from inside one of the childViewControllers, but it did not work. The app crashes. NSLOg shows that self.childViewControllers is just (), so it has no childViewControllers. I tried to NSLog 'self', and it logs "MainView", which does have the childViewControllers. I don't understand why I can't list the childViewControllers from there.

Could you help me out?
http://TallyBoardApp.com

- A game of Logic, Strategy and Math.

kjmcneish

  • Administrator
  • *****
  • Posts: 719
    • View Profile
Re: Container Views
« Reply #3 on: April 08, 2014, 10:22:52 PM »
If you send me a copy of the app (the version that crashes) I can take a look at it for you (kevin@iOSAppsForNonProgrammers.com).

All the best!
Kevin