Precautions for using storyBoard UITableView

Source: Internet
Author: User

Storyboard is very convenient to visually design the cells of tableview and tableview. However, some people may have come from hand-written code controls in the early days, so there are some important points here.

 

1. registerClass cannot be used

2. You do not need to judge if dequeueReusableCellWithIdentifier forIndexPath returns an empty cell, because it will certainly return a non-empty cell, and the cell after subclass should not write initWithStyle.

3. How can I know how to reuse cells in advance? Rewrite cell prepareForReuse

 

 

---------- Split line, followed by a specific explanation ---------------------------

 

1. registerClass cannot be used

 

When we use UITableView in storyboard mode, UITableViewCell cannot be registered using registerClass.

Generally, when you use UITableView in ios6, you can use the following method to register the reuse ID in viewDidLoad.

[Self. tableView registerClass: [RecipeBookCell class] forCellReuseIdentifier: @ "RecipeCell"];

This method is for manual use. When you use this registerClass registration, the Dynamic Prototypes drawn in the storyboard will no longer take effect.

 

- (}

 

 

2. You do not need to judge if dequeueReusableCellWithIdentifier forIndexPath returns an empty cell, because it will certainly return a non-empty cell, and the cell after subclass should not write initWithStyle.

 

Another thing to note is that in the handwriting code method, it usually determines whether the cell returned by tableView dequeueReusableCellWithIdentifier forIndexPath is null. If it is null, alloc and initWithStyle are called. (that is, if registerClass is used before, this judgment is required)

After using the Dynamic Prototypes of storyboard, it will never be called here, because dequeueReusableCellWithIdentifier forIndexPath will never return cells equal to nil to you.

At the same time, this means that initWithStyle will not be called after your UITableViewCell subclass is made, and you should not bother to write code in it.

 

 

 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath * NSString *simpleTableIdentifier = *cell = (cell ==    cell.nameLabel.text ===   

 

3. How can I know how to reuse cells in advance? Rewrite cell prepareForReuse

 

The official header file indicates that if the allocated cell is reused (usually scrolling out of the screen), the cell prepareForReuse will be called to notify the cell.

Note that when you override the method here, you must call the parent class method [super prepareForReuse].

Pay special attention to this when using cell as the proxy container for network access. You need to cancel the previous network request here and do not send data to this 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.