0. preface during project development, we often encounter that the basic space in some View is the same, but the data is different. In this case, we can use xib to encapsulate this View for multiple reuse, (For example, TableViewCell with fixed size controls) This can speed up the development progress of our project as much as possible. 1. The basic usage of xib is the File's owner in A. xib, which indicates that the control in xib can be connected to the attributes and methods of the ViewController class. Although it can be connected to the methods and attributes in this ViewController class, it does not mean that the methods in this class can be directly called. You must perform another operation. B. When loading xib, You need to input an owner object to call the method in this object. If you do not input own, a wild pointer error will be reported. Design xib. It is best not to bind the File's owner. Try to make the code less coupled, that is, the association is not close. 2. xib reuse 2. 1. create an xib 2. 2. create a RowView class that encapsulates the property rowView of xib. h copy code 1 # import <UIKit/UIKit. h> 2 3 @ interface RowView: UIView4 + (id) rowViewWithIcon :( NSString *) icon name :( NSString *) name; 5 6 7 @ property (nonatomic, weak) IBOutlet UIButton * iconBtn; 8 9 @ property (nonatomic, weak) IBOutlet UILabel * nameLabel; copy the rowView code. m copy code 1 # import "RowView. h "2 3 @ implementation RowView 4 5 + (id) rowViewWithIcon :( NSString *) icon name :( NSString *) name 6 {7 RowView * view = [[NSBundle mainBundle] loadNibNamed: @ "RowView" owner: nil options: nil] [0]; 8 9 // 1. set the Icon 10 // UIButton * iconBtn = (UIButton *) [view viewWithTag: 1]; 11 [view. iconBtn setImage: [UIImage imageNamed: icon] forState: UIControlStateNormal]; 12 13 // 2. set Name 14 // UILabel * nameLabel = (UILabel *) [view viewWithTag: 2]; 15 view. nameLabel. text = name; 16 17 return view; 18} copy Code 2. 3. in the Controller ViewController class, call the class to generate xib and reuse the copy Code # import "ViewController. h "# import" RowView. h "@ interface ViewController () @ end @ implementation ViewController-(void) viewDidLoad {[super viewDidLoad]; RowView * row = [RowView rowViewWithIcon: @" 017.png" name: @ "HAHAHA"]; [self. view addSubview: row];} copy the code by passing parameters to generate xib with different data types