3

I am currently using XCode 3.2.3 and iOS4. I'm working on an app that simply starts with one screen and on a button click moves to the next.

I have gone thorugh the ViewController programming guide and a post here.

What I am doing is very similar to whats happening on the post. So let me explain the steps, I followed:

  1. In IB, drag and drop, a View from the library into the editor. I renamed the new UIView to myView.

  2. In my AppControllerDelegate, I added the new view "myView" as a property of the view controller (File's Owner). I synthesized it as well in the implementation.

  3. Now, in the implementation of the ViewController, within the button pressed action handler, I wrote the following lines of code:

[self.view addSubView: myView];

  1. On clicking the button however, I do not see a new screen or my new view. However if I do this, I get a new screen or new view:

UIView *anotherView = [[UIView alloc] initWithFrame:self.view.frame]; [self.view addSubView: anotherView];

I do know that the best way is to do it with separate NIBs for each UIView. However, I am new to iPhone development and have not explored that path as yet.

My question: What am I missing upto step 3?

1 Answer 1

1

One way you could be able to do it is by trying it this way

myView = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle: [NSBundle mainBundle]]; [self.view addSubview: myView.view]; 

Try that and see if it is working.. if yours is a view based project then instead of [self.view addSubview: myView.view], just give [self.view addSubview : myView];

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, that's it i think... Here's what I did.. I created a new ViewController (.h, .m and .xib) and then added the statements above to my base ViewController code. It worked fine. Thanks.. One thing here, is that all ViewControllers to be added as subViews should be added as properties of tha app delegate.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.