initWithFrame - Initializes and returns a newly allocated view object with the specified frame rectangle.
The frame rectangle for the view, measured in points. The origin of the frame is relative to the superview in which you plan to add it. This method uses the frame rectangle to set the center and bounds properties accordingly.
Parameter is frame -
The frame rectangle for the view, measured in points. The origin of the frame is relative to the superview in which you plan to add it. This method uses the frame rectangle to set the center and bounds properties accordingly.
So You should call below like this
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
// Initialization code
NSArray *arrNibView = [[NSBundle mainBundle] loadNibNamed:@"DigitsKeyboardView" owner:self options:nil];
UIView *nibView = (UIView*)[arrNibView objectAtIndex:0]; //Give here your first object
[self addSubview:nibView];
}
return self;
}
If you have multiple custom views and If you want to use the custom view for separate controller you can use above method.
But If you have custom view and If you want to use(Reuse) multiple
times in multiple view controllers,you need to implement bot both the
initWithFrame and awakeFromNib method
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
// Initialization code
[[NSBundle mainBundle] loadNibNamed:@"DigitsKeyboardView" owner:self options:nil];
[self addSubview:self.view];
}
return self;
}
- (void) awakeFromNib
{
[super awakeFromNib];
[self addSubview:self.view];
}
initWithFrame - It is recommended that you implement this method. You
can also implement custom initialization methods in addition to, or
instead of, this method.
awakeFromNib - awakeFromNib gets called after the view and its
subviews were allocated and initialized. It is guaranteed that the
view will have all its outlet instance variables set.
Detailed Explanation of awakeFromNib
During the instantiation process, each object in the archive is
unarchived and then initialized with the method befitting its type.
Cocoa views (and custom views that can be customized using an
associated Interface Builder palette) are initialized using their
initWithCoder: method. Custom views are initialized using their
initWithFrame: method. Custom classes that have been instantiated in
the nib are initialized using their init method.
Once all objects have been instantiated and initialized from the archive, the nib loading code attempts to reestablish the connections
between each object’s outlets and the corresponding target objects. If
your custom objects have outlets, an NSNib object attempts to
reestablish any connections you created in Interface Builder. It
starts by trying to establish the connections using your object’s own
methods first. For each outlet that needs a connection, the NSNib
object looks for a method of the form setOutletName: in your object.
If that method exists, the NSNib object calls it, passing the target
object as a parameter. If you did not define a setter method with that
exact name, the NSNib object searches the object for an instance
variable (of type IBOutlet id) with the corresponding outlet name and
tries to set its value directly. If an instance variable with the
correct name cannot be found, initialization of that connection does
not occur. Finally, after all the objects are fully initialized, each
receives an awakeFromNib message.
Apple Documents
UIView
initWithFrame
awakeFromNib
Other Sources
Getting Nib File loaded
Initialize a view with xib
awakeFromNib Calling
viewDidLoad and awakeFromNib timing