开发者

ios4 - Load new view on clicking a button

开发者 https://www.devze.com 2023-02-26 09:01 出处:网络
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 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 t开发者_JS百科o 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?


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];

0

精彩评论

暂无评论...
验证码 换一张
取 消