creating a universal window-based iphone app without generated xib file

£可爱£侵袭症+ 提交于 2019-12-11 03:08:59

问题


I am trying to create a Window-based Universal app for iPhone/iPad. I used the Window-based template in XCode and it creates the necessary app delegate files for iPhone and iPad, but it also creates a xib file for each device, which I don't want to use -- I want to create my own views programmatically using my own view controllers, so I want to totally ignore the provided xib files.

I deleted the xib files from the project and updated the plist file accordingly to not reference them, thinking that now I can define my own views inside the app delegate, attach them to the window and display them. Not so -- that doesn't work -- my created views are not displayed. So I decided to just change the background color of the window to red and see if that shows -- it doesn't. Tracing code execution does show that this code is executed.

So, what can and should I do? Why is this happening?


回答1:


Change the

int retVal = UIApplicationMain(argc, argv, nil, nil);

in main.m into

int retVal = UIApplicationMain(argc, argv, nil, @"MyAppDelegate");

Then you have to initialize the window in the AppDelegate:

CGRect screenBounds = [[UIScreen mainScreen] bounds];
self.window = [[[UIWindow alloc] initWithFrame: screenBounds] autorelease];

Then you can add views to the Window.



来源:https://stackoverflow.com/questions/4418736/creating-a-universal-window-based-iphone-app-without-generated-xib-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!