First, the scope of application of Xib
Xib( also known as Nib) is used to describe the narrative interface as well as storyboard.
StoryboardDescriptive narrative is relatively large, large-scale. Suitable for descriptive narrative interface jumps, etc..
Second, the use of xib
XibIt's a small area .,it's lightweight..more suitable for describing small pieces of the interface.
Create Xib:New interface Insideuser interface--"empty."
loading xib:[NSBundle Mainbudle]loadnibnamed: XXX ....]to loadXib
Iii. About the Loadnibnameed method
[[NSBundle Mainbundle] loadnibnamed: @ "Myxib" Owner:nil options:nil]; //General usage
return value : The returned Nsarray is the number of views (without a child view) under the root view, for example, to return only 2, that is, view and button. (does not include a child view in the view)
owner : Specify the corresponding file ' s owner
Xib For example:
The use of the xnviewcontroller.m//09xib is simply loaded into the xib, without setting the Filesowner cannot be wired.////Created by Neng on 14-6-5.//Copyright (c) 2014 Neng. All rights reserved.//#import "XNViewController.h" @interface Xnviewcontroller () {BOOL _sign;//beta}@ End@implementation xnviewcontroller-(void) viewdidload{[Super Viewdidload]; _sign = NO; [Self myloadxib];} /** loading xib*/-(void) myloadxib{//1. Loading xib Nsarray *views = [[NSBundle mainbundle] loadnibnamed:@ "Myxib" Owner:nil optio Ns:nil]; 2. Remove the view from the Xib and add to the parent view UIView *myview = Views[0]; UIButton *BTN1 = (UIButton *) [MyView viewwithtag:1]; UIButton *btn2 = (UIButton *) [MyView viewwithtag:4]; [Btn1 addtarget:self Action: @selector (Myclick) forcontrolevents:uicontroleventtouchupinside]; [Btn2 addtarget:self Action: @selector (Myclick) forcontrolevents:uicontroleventtouchupinside]; [Self.view Addsubview:myview]; NSLog (@ "%d", views.count); The returned array is the number of views (without a child view)//And another one. (The order in the array is based on the order in the Xib file) UIButton*BTN = views[1]; Btn.frame = CGRectMake (0, 333, btn.frame.size.width, btn.frame.size.height); [Btn addtarget:self Action: @selector (Myclick) forcontrolevents:uicontroleventtouchupinside]; [Self.view addsubview:btn];} /**xib in the Monitor button click event, click to make storyboard in the label text changes */-(void) myclick{_sign =!_sign; if (_sign) {_mylabel.text = @ "hello!";} else{_mylabel.text = @ "world!";}} @end
4. About file ' s Owner
function: Let xib can also be wired like storyboard .. (StoryboardThe default build time,classfor the correspondingViewcontroller,so you can connect directly to the method in the code.).
Practice:
(1).will beXibin theclassset to the appropriateViewcontroller.
(2).and inloadnibwhen theownerset to the appropriateViewcontroller (that is, the generalSelf ,Object)。
File ' Ownernot limited toViewcontroller,can be no matter what kind of.
Classwhich class is defined,you can connect in which class.,and to be inloadnibwhenownerPass in the correspondingObjectyou can call the corresponding method. (Must be consistent, otherwise the method will not be found when calling the method)
Reprint Please specify Source: http://blog.csdn.net/xn4545945
The use of "IOS" xib with file& #39; Owner Summary