0

I'm doing some iPhone development, and I'm using Storyboards to mock up and expedite my development.

I didn't came from the conventional way of doing things, do I have to?

Anyway, I have storyboard,

                                                          TableViewController
NavigationController->ViewController->TabViewController [
                                                          AnotherViewController

I wanted to add a new ViewController attached to the TableViewController so that when I click on the row item it will show it on the other view, however;

  1. I can't find a way how to connect the new ViewController into the TableViewController (vice versa)

So I tried the conventional way of doing things on the

didSelectRowAtIndexPath:(NSIndexPath *)indexPath

I put the ff:

CViewController *controller = [[CViewController alloc] initWithNibName:????? bundle:nil];
[self.navigationController pushViewController:controller animated:YES];
[controller release];

I tried to give the Controller an identifier on the Attributes Inspector but does not work and is giving me the following crash stack:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/paulvincentong/Library/Application Support/iPhone Simulator/5.1/Applications/A1C369F8-9EAD-4794-8861-945C73F7FE0B/SyncProto.app> (loaded)' with name 'ControllerViewName' 

If I remove the Identifier, I'll get a no NibName exception;

What should I do? I know it should just be the same as I was able to go as far as four levels of relating controllers, there might be something at the back of my head that is confusing me...

TIA,

mirageservo
  • 2,387
  • 4
  • 22
  • 31

3 Answers3

0

try this in your cellForRow

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath  
*)indexPath{

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard" 
bundle:nil];

ViewCont * view = (ViewCont *) [storyboard   
     instantiateViewControllerWithIdentifier:@"view"];

[tableView deselectRowAtIndexPath:indexPath animated:YES];  

[self view animated:YES completion:nil];

}

Make sure you have set your storyboard also in the project manager.

Bad_APPZ
  • 432
  • 1
  • 3
  • 12
0

Are u using IB? There you can drag directly.

Otherwise in storyboards you don't use the push method you stated. You use performSegueWithIdentifier. Storyboards are about segues. You can segue directly or use target actions.

Again the strength of storyboards is in their visual representation. Use IB.

Otherwise you might also consider delegation (ESP for ipad).

Live2Enjoy7
  • 1,075
  • 2
  • 11
  • 22
0

After playing around... I found the suitable answer to my question;

My problem appears to be cause of

  1. Confusion - a new programmer's dilemma.. tho the question is a common one, we can never really deviate if its really the same with those already existing and asked before only up until we tried it ourselves and found out that it really was.

The solution could vary from case to case; and for me I tried to do the ff:

Approach 1: (using the "instantiateViewControllerWithIdentifier") with a segue arrow

  1. Create the view to be added
  2. Position your mouse pointer to the Nib element source view controller you want to trigger the segue then hold control
  3. Drag you mouse to the destination view controller
  4. A popup will appear, choose your segue type (push, modal, custom) then automatically xcode will create the necessary connections
  5. Select your destination view controller and on the Attribute Inspector there is a Collapsible group with Identifier field -> on this field you will put your custom identifier for the view

So the source code would look like;

ViewController *view = [self.storyboard instantiateViewControllerWithIdentifier:@"CustomViewName"];
[self.navigationController pushViewController:view animated:YES];

Approach 2: (using the "instantiateViewControllerWithIdentifier") without the segue arrow

  1. Create the view to be added
  2. Provide the new controller with the necessary identifier then you're good to go
  3. Using the same source as defined above

However, using this approach will break your storyboard's consistency and why use this? (still something I have to find out), its not obvious when you start looking for the segue arrow that was never there, albeit it works.

This code will not work on the basis that I don't have a nib with a name ????,

CViewController *controller = [[CViewController alloc] initWithNibName:????? bundle:nil];
[self.navigationController pushViewController:controller animated:YES];

and since its on a storyboard and assuming everything was done using the storyboard, then time to forget about the nibName because it will never happen..

Hope that this idea would help a few...

Learning is a thorough process yet its a very interesting thing to do...

Thanks.

mirageservo
  • 2,387
  • 4
  • 22
  • 31