i'm wondering if there's (simple) way achieve following using nsfetchedresultscontroller:
say have visitor log table this:
visitor_name (string) visit_time (date) visited_building_id (string) example data:
john, 2015-09-25 10:00:00, abc jane, 2015-09-25 10:20:00, abc mark, 2015-09-25 10:40:00, abc jane, 2015-09-25 10:10:00, def and want show table view shows visited each building, data above should show 2 rows:
[abc, mark, 9/25 10:40] [def, jane, 9/25 10:10]
one solution to:
- sort entries
visited_building_id(ascending or descending prefer) ,visit_time(descending). - specify
visited_building_idsectionnamekeypathfetched results controller. frc therefore have section each building, , first object in each section recent visit. want table view rows display first item in each section of frc. so... amend tablewview datasource methods remap frc sections tableview's rows. example
numberofrowsinsectionreturnfrc.sections.count.cellforrowatindexpathconstruct newnsindexpathusingnsindexpath *newindexpath = [nsindexpath indexpathforrow:0 insection:(indexpath.row)]or
let newindexpath = nsindexpath(forrow:0, insection:indexpath.row)and uses
newindexpathobtain object display in cell using frc'sobjectatindexpathmethod.
note remapping must repeated/reversed in other datasource methods. , means tableview can have 1 section.
Comments
Post a Comment