开发者

How to implement "Refresh" and "Reload" Table (re-factoring of code)

I have the following situation:

1) 1 X PhotoTableViewController to display a list of photos (one photo per cell) like what Instagram does

2) A refresh button in the navbar of PhotoTableViewController to do a table reload (top right)

3) An option button in the navbar of PhotoTableViewController to select a list of options e.g. "Latest photos, most popular etc) (top left)

How to implement "Refresh" and "Reload" Table (re-factoring of code)

4) A "Load more" cell at the end of the list (limit to 20 photos) to append the next set of photos to the table view.

How to implement "Refresh" and "Reload" Table (re-factoring of code)

The photos are obtained from a server and comes in a form of a JSON file.

Query: I believe that all 3 buttons (point 2,3 and 4) essentially want to do the same thing, which is to refresh and reload the table. Also my understanding is that this is a common sort of practice in a few apps, so I would like some advise on the following

1) How do I implement this sort of 'Refresh' and 'Reload' method in the most effective way without repeating code.

2) After I click each button, the intenti开发者_如何学Goon is to sort of have a 'Blank page' with a spinner and show only the reloaded table after processing is completed. I am thinking of popping the current tableview controller at point of button click and push a new controller back once processing is completed. Does this make sense? Or is there a better way of doing it?


You are correct that they all essentially have the same behavior. I would say that you implement a cursor type of backend call so that you can pass in the next result number you want or the next page you want. That is up to you, but here's a sample.

{
"cursor": {
    "currentPageIndex":0,
    "estimatedNumberOfHits":351,
    "pages":[{
        "label":"1",
        "offset":0
    },{
        "label":"2",
        "offset":10
    },{
        "label":"3",
        "offset":20
    }]
},
"details":"",
"data":[{
    "id":709,
    "modifiedOnTimestamp":1304009527000,
    "state":"California",

    "city":"Santa Monica",
}]

Create the network call in one place (on iOS side) that passes in the result number you want next. Then, when you process the JSON, they call call reloadData on the table view.


Would this work?

-(IBAction)reloadTableOnButtonPress:(id)sender {

    // Present a dark modalView

    [tableView reloadData];

    // Trigger to dismiss modalView

}


[tableView reloadData] should do the trick. This method re-runs all the delegate and data source methods on the table, and updates the appearance of the table accordingly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜