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_id
sectionnamekeypath
fetched 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
numberofrowsinsection
returnfrc.sections.count
.cellforrowatindexpath
construct newnsindexpath
usingnsindexpath *newindexpath = [nsindexpath indexpathforrow:0 insection:(indexpath.row)]
or
let newindexpath = nsindexpath(forrow:0, insection:indexpath.row)
and uses
newindexpath
obtain object display in cell using frc'sobjectatindexpath
method.
note remapping must repeated/reversed in other datasource methods. , means tableview can have 1 section.
Comments
Post a Comment