Create and register UITableViewCell and storyboard and xib differences
//interface Creation Complete is called- (void) viewdidload{[Super Viewdidload]; /** If a prototype cell is registered for TableView in the following 3 ways, the system uses the registered cell as the cell for display and the reusable cell, once the buffer does not have a reusable cell, The system uses the registered prototype cell to instantiate a cell for use by the program! So as long as the prototype cell is registered, cell = = Nil is no longer needed to create the cell. */ //1. The Pure Code custom cell registration is as follows:[Self.tableview Registerclass:[hmstatuscellclass] Forcellreuseidentifier:id]; //2. Using Xib custom cell, register the following[Self.tableview registernib:[uinib Nibwithnibname:@"Wzusercell"Bundle:nil] forcellreuseidentifier:usercellid]; //3. Use storyboard to create the Protocell, just set the Protocell reuseidentifier, the system automatically register. }#pragmaMark-Data Source Method-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) Section {returnSelf.statusFrames.count;}-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath {//The official recommendation is to use the following method, which requires that reusable cells must be pre-registered, otherwise crashes! Crashes before the program is released to help identify problems. Hmstatuscell *cell =[TableView dequeuereusablecellwithidentifier:id Forindexpath:indexpath]; //Hmstatuscell *cell = [TableView dequeuereusablecellwithidentifier:id];//once you have registered a reusable cell, the above two methods are equivalent//if (cell = = nil) {//cell = [[Hmstatuscell alloc] Initwithstyle:uitableviewcellstyledefault Reuseidentifier:id]; //} //If you register a prototype cell, you do not need to create it and use it directly. returncell;}
There are significant differences in the tableview shown in storyboard and xib:
Various navigation/tabbar/View controllers (scene scenes) can be placed in the storyboard, which can be used to set the relationship between the various interfaces, which is a heavyweight IB tool.
Xib is typically used to set small, local UI, such as Cell/footerview/headerview that define a tableview. In addition, even if you drag Uitableviewcontroller into the xib, you can not add Protocell or ordinary cell, forcibly dragged into the immediate error (Error:illegal configuration:table views With embedded sections and cells is only supported in storyboard documents). Another drag into the Xib Uiviewcontroller does not seem to embed in the navigation controller.
Storyboard (Uitableviewcontroller) such as:
Xib (UITableView) such as:
[BS-13] Create and register UITableViewCell and storyboard and xib differences