开发者

Data driven UITableViewController implementations?

开发者 https://www.devze.com 2022-12-19 12:24 出处:网络
I have a UITableViewController whi开发者_运维技巧ch is starting to get a bit crazy with all the switch statements for each UITableView delegate.

I have a UITableViewController whi开发者_运维技巧ch is starting to get a bit crazy with all the switch statements for each UITableView delegate.

Does anyone have any suggestions or examples of more of a data driven implementation for a UITableViewController? I'm thinking some type of data structure which would hold references of where to go to get cells for certain section/rows, where to get the section names, etc.

I think the More iPhone Development book describes something like this, just wanted to poll the community and see if anyone had some lessons learned on their own implementation.


I don't think there is a standard one that is generally suitable for everyone, but it's not too hard to whip up your own to suit the needs of your application. Basically, you want an array/list of sections, and for each section, an array/list of items. For each item, you'll want to allow specification of an image, text, detail text, and some sort of action to be fired upon selection.

If you want to get fancy, you can specify background colors, fonts, and other such things for each section heading, section footer, and item.

If your list items don't all look the same, then your tableView:cellForIndex: implementation needs to be smart enough to use different reuse identifiers for different-looking items.

A nice thing about this approach is that you can often use the same view and same controller for many "screens".

Consider using Core Data and NSFetchedResultsController.


Core Data's NSFetchedResultsController will do most of the data work for you. It might be overkill if your model is simple or not persisted though.

0

精彩评论

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

关注公众号