Linux world
Linux world

Reputation: 3768

how to load a view using a nib file without using view controller

i am new to this objective-c i want to load a view using nib file i created when i press a button .without using any view controller..

Upvotes: 2

Views: 2874

Answers (2)

RyanCars
RyanCars

Reputation: 41

Try this. Should show you how to implement your UIView subclass.

http://markuzweb.blogspot.com/2011/05/subclassing-uiview-with-nib-file.html

Upvotes: 4

Lily Ballard
Lily Ballard

Reputation: 185831

This is generally considered a bad idea if you don't know what you're doing, but if you really want to do this then there's 2 places to look, depending on what version of the OS you're developing for.

iOS 4

Look at UINib in the documentation. You can use this to load a nib fairly easily.

iOS 3.2 and earlier

Use NSBundle. There is a category, documented under the name "NSBundle UIKit Additions Reference", that adds a method -loadNibNamed:owner:options:. You can also use this on iOS 4.0 if you so desire.

In both cases, the owner object fills in the role of "File's Owner" in the nib, useful if you have actions or outlets specified on the owner. The method also returns an NSArray of all the top-level objects in the nib. Be careful, if you use this array you need to retain any of the objects that you want to keep, as the array (and all the objects) are returned autoreleased.

Upvotes: 10

Related Questions