开发者

Call 2nd XIB and Class

I am teaching myself Obj-C slowly, I have a project with 2 Classes and each class has a XIB that goes with it.

For ease of testing, they are named One and Two

I changed the plist to make the app start on Two rather than One and that works.

So I am sure (I hope) that both classes and XIBs are OK.

So from One I want to call (view open or whatever its called in ObjC) the Two class and the XIB that goes with it. And then I want to be able to go back to One. Should be simple eh? I have messed with this for 2 days and still havent got it working.

Does anyone have a sample code that shows how to do this? I have found several docs on this but I guess I am being slow as I cannot figure it out.

thank you for any help!


More Info: EDIT: bm is the 2nd XIB

    bm *screen = [[[bm alloc] initWithNibName:@"bm" bundle:nil] autorelease];

I added the above code and then got this error on 开发者_开发百科this line

2011-05-09 14:48:23.242 HW[7265:207] * -[bm initWithNibName:bundle:]: unrecognized selector sent to instance 0x392e820 2011-05-09 14:48:23.244 HW[7265:207] Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '** -[bm initWithNibName:bundle:]: unrecognized selector sent to instance 0x392e820'


There are two ways to do this and it all depends on what you want it to look like.

Present the second view as a modal view controller:

ViewControllerName *viewController = [[[ViewControllerName alloc] initWithNibName:@"ViewControllerName" bundle:nil] autorelease];
[self presentModalViewController:viewController animated:YES];

Or you can actually swap the view out of the UIWindow:

UIWindow *window = [[[UIApplication sharedApplication] delegate] window];
ViewControllerName *viewController = [[[ViewControllerName alloc] initWithNibName:@"ViewControllerName" bundle:nil] autorelease];
window.rootViewController = viewController;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜