"We all love Paul Hegarty." Stanford IOS8 public class personal note tableviewdatasource

Source: Internet
Author: User

TableView is a very important part of iOS development.

TableView's role is to show the data in a table, which is a subclass of Uiscrollview, and you'll see that you can get more content by swiping the screen up and down when there are more cell entries in the table.
Table can be static or dynamic (such as the number of item in a table).
A very diverse table style can be created by DataSource and delegate.
Table is still very effective when displaying a large number of data levels.

This shows the dynamic and static table, the dynamic table is usually a long list, you can add and subtract entries, static table is used as some function items, the location of these feature items are fixed.
Here's a look at the parts of table, first of all the table headers:

There are corresponding attributes in TableView to manage the header, and there are, of course, footers, all of which are uiview:

Then the contents of the table are placed in the section, the number of sections need to implement the corresponding proxy method in DataSource, and this method is required:

Section also has headers and footer, the middle part is TableCell.

Setting up the cell is a very common proxy method, note that this method is a method in DataSource.
All we have seen are plain-style table, below is the grouped-style table.

Here is the difference between a table with section and no section:

The cell itself has many kinds, such as display:

Or use a format you define yourself.
You can drag and drop a tableviewcontroller this handy class in the object library, We know that the underlying view in Viewcontroller is obtained using Self.view, in fact Tabelviewcontroller this self.view is a uitableview, its size will be filled with the entire screen.
As before, when we use the TableView in this storyboard we need to correlate this scenario with a subclass of Uitableviewcontroller, one of the benefits of using the edit class is that The subclasses you associate with will become the DataSource and delegate of this tableview, without the need to manually add
somTableView.delegate = self
Such a code.
You can set the properties of the TableView in the property inspector.
There are several important attributes that need to be followed, such as
Style: You can set plain and grouped

Content: You can set dynamic and static

Note that if you set it to static, your tableview can only be set in storyboard, and you will be able to add a variety of controls to it.
If set to dynamic, you can set it in the controller's code, usually dynamic table using the style plain. The cell is now reused multiple times.
You can edit these cell formats and in the attempt to select the cell in the outline, the property inspector switches to the cell:

For example, this accessory, choose a different style, the right side of the cell will appear a different icon, are our very common format:


If you use a custom cell format, you need to correlate a subclass of cell and class UITableViewCell.
Then open the Union editor and associate the elements in the cell in your newly created subclass:

Note that the UITableViewCell here is not a controller, so it does not have a method in the controller life cycle (such as viewdidload), it has a method awakefromnib, this method will be called before the layout in storyboard, You can override another method, Layoutsubviews, which is called after the page auto-layout is complete.
About TableView:

Note that there is an attribute in Tableviewcontroller TableView that is Self.view represents the default table in the controller.
There are three important methods in DataSource that must be rewritten: they stipulate
How many sections are in 1table
2 How many lines are in each section
3 Specify a view to draw the cell style for each row in each section
Here's a question about the cell's style:

The controller sets the cell style for a row using the DataSource method.
In this method you can prepare a data structure for presentation in advance, which is a two-dimensional one that can take out the corresponding cell style for a section and row:

We can reuse the existing cell format when we create the cell:

Use dequeued to record the format of a reusable cell, but notice that we explicitly label its type, which makes a anyobject type. When creating a cell, it is necessary to convert the dequeued type into a cell type, such as when the cell is a non-custom cell, to convert to the most basic UITableViewCell, You can then use the UITableViewCell API:

For a custom cell:

The same is true with identifier, and the difference is that you need to convert the type to the type it needs, and then use the APIs in the subclass:

Except cellfor ... This method, take a look at the other two methods in DataSource:

Section has a default value of 1, you do not override this method, the number of sections will be set to 1. But the number of row does not have a default value, so you must override this proxy method.
However, for a static table, do not override these methods and set them directly in the storyboard.
With DataSource, showing a table becomes very simple:

Includes the title and footer of the section.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

"We all love Paul Hegarty." Stanford IOS8 public class personal note tableviewdatasource

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.