The parsing process and use of File ' s owner:
1.
Storyboard: Describe the software interface; iOS5.0.
Xib: Description software interface; Storyboard predecessor.
2.
All resources within the project environment are accessed through [NSBundle Mainbundle], such as the full path to the image;
= = = There is one way: loadnibnamed: (nsstring*) Owner: (ID) Option: (nsdictionary*) = = =
3. If a control in Xib wants to connect with the controller:
1> Xib's file ' s owner must set class to the appropriate controller;
2> loadnibnamed: (nsstring*) Owner: (ID) Option: (nsdictionary*) The owner is to be set to the appropriate controller (because this parameter does not pass, when the file ' s owner is still empty );
3> Xib sets the class of file ' s owner, then the controls inside the Xib can find the appropriate method to invoke in the file's owner (class or object, such as the Dog object).
4. The essence of Xib is XML, the parsing process is as follows:
--------------------------------------------------------------------------------------------------------------- ---------------------
5. File ' s owner use steps:
Note: Type matching means: The type to be set in the class of file ' s owner is the same as loadnibnamed: (nsstring*) The type of owner parameter in Owner option: (nsdictionary*).
Second, the view of the package (custom view)
Preface: The controller should not be used to monitor the click of the button in the Xib, because the Xib and the controller are bound dead, the coupling is too strong, which is not conducive to extended reuse.
--------------------------------------------------------------------------------------------------------------- -----------------------------------------------
For easy viewing, simply describe the overview of customizing view with Xib:
=======ROWVIEW.M and RowView.h file contents and Xib file ======
#import "RowView.h"
@implementation Rowview
+ (ID) Rowviewwithicon: (NSString *) icon Name: (NSString *) name
{
Rowview *view = [[NSBundle mainbundle] loadnibnamed:@ "Rowview" Owner:nil options:nil][0];
#if 1//If the Drag line connection property and Xib
//1. Set icon
UIButton *iconbtn = (UIButton *) [view viewwithtag:1];
[view.iconbtn setimage:[uiimage Imagenamed:icon] forstate:uicontrolstatenormal]; //Note: Class methods cannot access member variables! so you can't use _iconbtn
//2. Set name
UILabel *namelabel = ( UILabel *) [view viewwithtag:2];
view.nameLabel.text = name;
#else
1. Settings icon
UIButton *iconbtn = (UIButton *) [view viewwithtag:1];
[View.iconbtn setimage:[uiimage Imagenamed:icon] forstate:uicontrolstatenormal];
2. Set the name
UILabel *namelabel = (UILabel *) [view viewwithtag:2];
View.nameLabel.text = name;
#endif
return view;
}
@end
----------------------------------------
#import <UIKit/UIKit.h>
@interface Rowview:uiview
+ (ID) Rowviewwithicon: (NSString *) icon Name: (NSString *) name;
@property (nonatomic, weak) Iboutlet UIButton *iconbtn; If it's not a tow line, No.
@property (nonatomic, weak) Iboutlet UILabel *namelabel; //Don't drag the line.
@end
----------------------------------------
Rowview.xib:
Usage in the controller:
-(void) viewdidload
{
[Super Viewdidload];
Rowview *row = [Rowview rowviewwithicon:@ "017.png" name:@ "Jake"];
[Self.view Addsubview:row];
}
Use of Ios-xib