开发者

How to start an iphone app so that it doesnt use any nib files?

开发者 https://www.devze.com 2023-04-01 03:31 出处:网络
I\'ve been reading about pros/cons of programming with/with开发者_运维技巧out an interface builder and i want to try writing an app from scratch. however, even with a window based application it creat

I've been reading about pros/cons of programming with/with开发者_运维技巧out an interface builder and i want to try writing an app from scratch. however, even with a window based application it creates a xib file and i would like to remove this but not sure what to do after. just really need that jump start. Thanks!


Fundamentally you have to specify the appDelegate in UIApplicationMain() (in main.m), that is... from:

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

to:

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

then in MyAppDelegate's method application:didFinishLaunchingWithOptions: you have to manually create your UI:

// initialize application's window
_window = [[UIWindow alloc] initWithFrame:MAIN_FRAME];

// activate and display application's window
[_window makeKeyAndVisible];

...and so on


There are few ways, one of the simple ones: Go to the project files navigator, look for

"Supporting Files -> XXX-info.plist", 

then look for this:

Main nib file base name: 

Remove this.

Hope this help


You can create any project and while you add new viewController just uncheck the checkbox which says "With XIB for UserInterface" (shown below with a red arrow).

This would allow you to create viewControllers without the XIB.

But then you will have to put all the controls programmatically for the viewController

How to start an iphone app so that it doesnt use any nib files?

Dont use the viewController which comes in by default and add newViewController with the method mentioned above.

Then start creating controls you want like UIButton, UILabel, etc using its allocation(alloc) and initialization(init) methods and set its frames.

Then you need to set any attributes as per your requirement and then just add it as a subview to your main view of the viewwController. So it would be something like say adding a textField dynamically would be:

UITextField *txtField = [[UITextField alloc] initWithFrame:CGRectMake(150,30,40,24)];
txtField.textColor = [UIColor blueColor];
[self.view addSubview:txtField];

Hope this helps you.


Hopefully following step will be useful.

  1. Open ProjectNameInfo.plist file and then remove the property called Main nib file base name (toward the bottom of the Information Property List). You can remove a property by clicking to select it and then pressing the Delete key.

  2. Under Other Sources, open main.m, and change the last argument of the call to UIApplicationMain from nil to the name of your application delegate class (for example, @"ProjectNameAppDelegate").

  3. Do following changes in AppDelegate class didFinishLaunchingWithOptions: method

//Get Rects of screen

CGRect screenBounds = [[UIScreen mainScreen] bounds];

//Allocate Window

m_window = [[UIWindow alloc] initWithFrame: screenBounds];

//Allocate custom Views

m_view = [[MyView alloc] initWithFrame: screenBounds];

//Add View And make window visible

[m_window addSubview: m_view];

[m_window makeKeyAndVisible];

return YES;

-> I learned it from book iPhone 3D programming: Philip Rideout : O'Reilly publication.

You should find above in goole books and read some pages for further understanding because only above explanation may not be enough.

Moreover, After doing above steps you can make any number of view controllers and views without using xib...so refer to various programming guide documents provided by apple.

Good Luck


I've made some nib-less project templates for Xcode 4: MinimalisticXcodeTemplates (GitHub).

0

精彩评论

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

关注公众号