objective c - Something doesn't feel right about how I am dynamically populating an NSTableView -
here object hierarchy: nswindowcontroller owns nsviewcontroller, data source & delegate nstableview.
nswindowcontroller fetches data internet, , passes nsviewcontroller can populate nstableview. happens asynchronously, nstableview loaded 0 rows.
nsviewcontroller owns nstableview, nsarray (as data source). both of these properties private.
from here i'm not confident in implementation: once nswindowcontroller has finished fetching data, call public method on nsviewcontroller named -addstringtoarray:(nsstring*) (to avoid making array public , directly calling -addobject on nsarray). -addstringtoarray calls -addobject on private nsarray, , also calls [self.tableview reloaddata]. call @ location i'm sketched out (though gladly take input on part of solution here)
because when nstableview loaded, has 0 rows, when data source (nsviewcontroller) method -numberofrowsintableview gets called, returns 0. in turn makes delegate method -viewfortablecolumn... never gets called, because (i'm assuming) thinks there 0 rows.
to method called, need call nstableview's -reloaddata.
tl;dr: table gets loaded 0 rows. add strings array. every time string added call reloaddata. calls -numberofrowsintableview, returns size of array. allows -viewfortablecolumn... called, returns appropriate string populates table.
am dynamically adding items nstableview in best way possible?
your approach fine. assuming you're targeting deployment 10.7 or later, can use -[nstableview insertrowsatindexes:withanimation:] after changing data model. avoids full reload of data.
Comments
Post a Comment