This chapter begins with the controller uitablecontroller that we use most in iOS. This chapter prepares the message page in the implementation. Let's start by analyzing the message interface. It uses the most common list layout that is currently available. The leftmost side of each line is a picture. The upper-right corner is the time of the most recent piece of information. The middle is the title and the body. You'll notice that many apps are used for this layout.
After the analysis, we'll see how to do it. First select the Uitablecontroller of the display message menu we created earlier. Such as:
The selected cell is the template we use, we can drag inside the various controls to form our interface, and then load the data back into the background file. Set ID to cell for the cell first
The layout is roughly as effective as. The approximate step is to set the row height to 60. The constraints of the other controls are shown in the code.
Then adjust the font for the body and the date. Sets the color of the body and date to gray, as in the effect.
Then set the tag for the next 4 controls. The background needs to be tagged to get the corresponding control. Set to 100 to 103, respectively.
The interface layout is here. Then you set the background file. The file creation process is not duplicated. Next, we introduce how the next Uitableviewcontroller file is implemented.
In fact, the logic is very simple, you need to implement what function. Just rewrite the uitableviewcontroller corresponding method. Describe a few common methods,
Numberofsectionsintableview (Tableview:uitableview), Int
This method shows how many sections are in this table. As for what is section? He is a top-level structure and can go to the Discovery menu, which is a 4 section.
TableView (Tableview:uitableview, numberofrowsinsection section:int)-Int This method is a description of how many rows are in each section. These two methods are basically for sure. Other methods can refer to the corresponding data. The following code:
First, define an entity class to load our data. Such as:
Then we begin to start the implementation of our background file class, first defining a global data source. Class in the Viewdidload function.
Then set the number of sections and the number of rows per section
Binding a data source for each row
The default height is used when the row height is defined and the system is not set.
The background logic is finished, and then we can't wait to run the effect. Strange, what's wrong? How does the text on the top overlap? Oh, the last step is missing, give our Uitableviewcontroller a navigation shell, and this is what we see in the top with the return function of the navigation. Check out our Uitableviewcontroller. Then select the Navigation Controller option in the menu.
Then we will find that our table has a navigation item. Select Him to set the title. For example:
Well, run down the effect. You alright? It is necessary to explain that the effects running in the real machine are not the same as in the simulator, with split lines in each line. This is why I recommend to use the real machine as much as possible.
It looks like it's not quite the same, oh, the navigation is black. We selected navigation bar to set style to black
Again to run the effect, is not good-looking?
Careful classmates will find that there is still less a thing, search function, don't worry, and so the next chapter we continue.
Code Address: Https://github.com/xing98218/FirstClass
iOS Development Series-uitablecontroller-1