0

I have two view controllers on the same storyboard. What I want to do is send an array of string values to the table view control on another view controller.

    ViewController2 *second=[self.storyboard instantiateViewControllerWithIdentifier:@"View2"];
    second.arrayFromVC1=areaArray;
    [self presentViewController:second animated:YES completion:nil];

The second view controller has a toolbar control at the top by default. (See below.)

2nd view controller

Passing data to another view controller wasn't easy for me, who has been using Xcode for two weeks. I somehow managed it. So an array of strings is sent to the 2nd view controller through an array variable (arrayFromVC1) set on the 2nd implementation file. I suppose experienced Xcode users know what I'm talking about. Anyway, the 2nd view controller does receive a list of values as shown below.

enter image description here

Well, the problems are that the toolbar control on the 2nd view controller will disappear when the user gets to see the list and that the table view control (UITableView) occupies the entire window. I understand that you can control the size of the table view control by specifying values under the viewDidAppear method. But my question is... Is that how things work with iOS and Xcode? So if I want to display that toolbar control at the top, I have to do it programmatically by writing code under the viewDidAppear method as well?

Thank you for your advice.

Tom

El Tomato
  • 6,479
  • 6
  • 46
  • 75
  • Is a solution answered by **more tension** in [this page](http://stackoverflow.com/questions/5958956/how-to-add-a-uitoolbar-to-a-uitableviewcontroller-programmatically) what I need? I do get a toolbar. I don't know how to get the back button to work so that the user can click on the item button to go back to the first view controller, though. – El Tomato Nov 24 '12 at 22:30

1 Answers1

2

Tom, are you using interface builder and storyboards? If so, select the ViewController in IB, go to Editor (in the top menu) --> Embed In --> Navigation Controller.

This will embed the chosen VC and any VC it segues to (and so on) into a Nav Controller.

Live2Enjoy7
  • 1,075
  • 2
  • 11
  • 22
  • I'm using Xcode 4.5.2. So, no, I don't have Interface Builder. – El Tomato Nov 24 '12 at 22:26
  • I'm using Xcode 4.5.2. So, no, I don't have Interface Builder. But I'll find out how the segues thing works. Thanks. – El Tomato Nov 24 '12 at 22:34
  • 4.5.2 has interface builder. When you first create project you check "Use Storyboards". Your first screen shot is from interface builder. Did you try selecting your view controller going to Editor at the top, and embedding it into nav ctrl? – Live2Enjoy7 Nov 24 '12 at 22:41
  • so try delete your current navigation toolbar and doing the embed. Create a snapshot first, so you can go back later if something (File-->Create A Snapshot) – Live2Enjoy7 Nov 24 '12 at 22:43
  • I see what you mean. I thought you were talking about an application in older versions separate from Xcode. Sorry about that... Anyway, I'll find out how the segues thing works. Thanks. – El Tomato Nov 24 '12 at 23:01
  • Okay. There's a sample project called 'CollectionView-Simple' in the iOS Development Library. It utilizes the segue thing to pass data. – El Tomato Nov 25 '12 at 00:28
  • I get it. So if you choose Embed In > Navigation Controller, Xcode will automatically insert the navigation controller to each view controller. – El Tomato Nov 25 '12 at 01:45
  • Nope. The navigation bar will quickly disappear on the 2nd view controller. – El Tomato Nov 25 '12 at 02:08
  • Okay. I think I've got it by embedding Navigation Controller. Thanks. – El Tomato Nov 25 '12 at 05:39