This article is reproduced from:
Flyblog
[
Http://www.flyblog.info
]
When I started learning about iPhone development, I figured out the appstoreProgramHow to achieve this by dynamically capturing content from the server and then displaying it in the table.
With the popularity of Twitter, more and more software has implemented this method to display Twitter messages,
Unfortunately, the company also wants to do Twitter-related things, taking this opportunity to test the implementation of such a display function.
The biggest difference between iPhone and traditional desktop programs is limited memory,
Memory Management is a constant task for iPhone development. Similar functions are nothing more than caching down data in the memory on the desktop program. You can just draw them out when necessary.
This method is not feasible on the iPhone, although uitableviewcell can be reused with reuse to save memory usage,
However, the data still needs the host in array or dictionary, which will inevitably cause the program to crash and exit when a large amount of memory is used.
Fortunately, the iPhone system has built-in SQLite micro-database. It is a sin to make such a good query insertion engine useless...
The basic idea is to read content from the server. Take Twitter as an example to create a message data table first.
Create Table public_timelines (ID integer primary key autoincrement, user varchar (40 ),/
Userurl text, body text, created real, created_string text ,/
Imageurl text, ordernum int, userid varchar (20), user_screenname varchar (40 ));
Get public timelines to get the message entries that exist in XML format. parse the XML and insert each message into the data table. After successful writing, the system sends a reload message to the table to re-fill the table unit content,
If more than one message record exists, remember to go to-(nsinteger) tableview :( uitableview *) tableview numberofrowsinsection :( nsinteger) Section
The returned message record is + 1, because the last cell needs to implement get more... Function
As mentioned in the previous step, click the last cell, that is, get more... Obtain the new timelines from the server, parse it into the data table, and clear the data table every time you refresh it. Otherwise, more messages will be displayed :), get more is probably in this state.
In this way, the memory used by the program is very small. Each message is read from the database file as needed. Reducing the memory usage increases the stability of the program, this is essential for successful software.
This article only gives a brief introduction to such an implementation technology. There are still many details to consider, such as: encapsulation of SQLite for ease of use;
The nsurlconnection method is used to download data and post data. XML parsing can also be performed using the nsxml * series APIs of the iPhone SDK.
You can also use libxml, depending on your habits. For Twitter, there are already many good open-source libraries available for direct use, such
Twitterengine