After the completion of the "Weibo focus on people" this application although the final completion of the distance is not small, but the visual has been compared to the completion of the exercise (1) a great improvement. :]
Careful friends in the last walkthrough, we have found that there is a field named "category" in the data structure that we define, and the setting of this field is primarily used to help us better manage our objects of concern. The walkthrough in this article simply involves a question of how to display data in a section in a table by category. After this walkthrough, I am sure you will have a new understanding of the use of arrays (Nsmutablearray) and plist files in iOS.
A. Before we begin
Before we begin, we need to briefly review some of the things we did last time, so we could start the walkthrough.
1. In the Focususers.plist file in order to store all the attention of the user data;
2. We define a class called Joyfocususer to store information for each user;
3. We use a Nsmutablearray array in the view controller to store the contents of plist files, and through the Joyfocususer class as a mapping to facilitate access to program writing process.
So now the problem is--the data loaded from the Plist file is a sequence, and when the segment is displaying the data, the array of a single sequence is obviously somewhat incompetent, and we need to do a relay. As shown in the following illustration:
If we change from a single sequence in the previous lecture to a two-dimensional sequence problem shown in the graph, it seems to be a good solution. :]
Well, there's a train of thought, now let's do it right away.
Two. Data adjustment
1. In the navigation area, click on the "focususers.plist" file to open the Plist file we created in our last walkthrough;
2. Click the right mouse button on "focususers.plist" and select "Open as" "Source code" and replace the plist content we last used with the following code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<array>
<dict>
<key>UserName</key>
<string>Love Apps</string>
<key>Image</key>
<string>Love Apps.jpeg</string>
<key>WebSite</key>
<string>http://weibo.com/iapps</string>
<key>Favorite</key>
<real>3.5</real>
<key>Category</key>
<string>Apple Consulting</string>
</dict>
<dict>
<key>UserName</key>
<string>Apple Exchange</string>
<key>Image</key>
<string>Apple sink.jpeg</string>
<key>WebSite</key>
<string>http://weibo.com/appleus</string>
<key>Favorite</key>
<real>3.5</real>
<key>Category</key>
<string>Apple Consulting</string>
</dict>
<dict>
<key>UserName</key>
<string> Digital iPhone Encyclopedia </string>
<key>Image</key>
<string> Digital iPhone Encyclopedia.jpeg</string>
<key>WebSite</key>
<string>http://weibo.com/gx110</string>
<key>Favorite</key>
<real>3.5</real>
<key>Category</key>
<string>Apple Consulting</string>
</dict>
</array>
<array>
<dict>
<key>UserName</key>
<string> Sina Vision </string>
<key>Image</key>
<string> Sina vision.jpeg</string>
<key>WebSite</key>
<string>http://weibo.com/wboard</string>
<key>Favorite</key>
<real>3.5</real>
<key>Category</key>
<string>official agency</string>
</dict>
</array>
<array>
<dict>
<key>UserName</key>
<string>Li Kaifu</string>
<key>Image</key>
<string>Li Kaifu.jpeg</string>
<key>WebSite</key>
<string>http://weibo.com/kaifulee</string>
<key>Favorite</key>
<real>3.5</real>
<key>Category</key>
<string>IT celebrities</string>
</dict>
</array>
</array>
</plist>
Comparing the plist file we used in the last walkthrough, we introduced a layer of array definition, which adjusts the original one-dimensional data sequence to a two-dimensional sequence. What do you think? It's not bad. :]