iOS Learning Table View Controller, table view cell

Source: Internet
Author: User

A Table View Controller, like many objects, had more than one Init method. There is:

Initwithcoder, for view controllers that is automatically loaded from a storyboard

Initwithnibname, for view controllers so manually want to the load from a nib (a nib was like a storyboard but Only contains a single view controller)

Initwithstyle, for table view controllers so manually want to create without using a storyboard or nib

There is four ways so can make table view cells:1. Using prototype Cells. This is a probably the simplest and quickest. You do this in Checklistviewcontroller.

2. Using static cells. You have the Add/edit Item screen. This is limited to screens where your know in advance which cells you'll have. The big advantage with static cells is, you don't need to provide any of the data source methods (Cellforrowatindexpat H and so on).

3. By hand, what do you do above. were supposed to do it before IOS 5. Chances is you'll run across code examples that does it this to, especially from older articles and books. It's a bit more work and also offers you are most of the flexibility.

4. Using a nib file. A nib (also known as a XIB) is like a storyboard but it's only contains a single view controller or in the this case a single CU Stom UITableViewCell object. This is the very similar to using prototype cells, except the can do it outside of a storyboard.

When you create a cell by hand you specify a certain cell style, which gives you a cell with a preconfigured layout that a Lready have labels and an image view. For the all Lists View controllers you ' re using the "Default" style, but later-tutorial you ' ll switch it to "subtitl E ", which gives the cell a second, smaller label below the main label.

Using standard cell styles means, you don ' t has to design your own cell layout. For many apps these standard layouts is sufficient so, saves you some work. Prototype cells and static cells can also use these standard cell styles. The default style for a prototype or static cell is ' Custom ', which requires you to use your own labels, but can Chang E that to one of the built-in styles with Interface Builder.

And finally, a warning:sometimes I see code This creates a new cell for every row rather than trying to reuse cells. Don ' t do that! Always ask the table view first whether it have a cell available that can be recycled using Dequeuereusablecellwithidentifi Er. Creating a new cell for each row would cause your app to slow down, as object creation was slower than simply re-using an ex Isting object. Creating All these new objects also takes to more memory, which are a precious commodity on mobile devices. For the best performance, reuse those cells!

iOS Learning Table View Controller, table view cell

Related Article

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.