[BS-13] Create and register UITableViewCell and storyboard and xib differences

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.