Here's the background: I'm initializing and setting the dataSource in my TTTableViewController
like so:
- (void)createModel {
TTSectionedDataSource *dataS开发者_C百科ource = [[[TTSectionedDataSource alloc] init] autorelease];
dataSource.model = [[[LogsModel alloc] init] autorelease];
self.dataSource = dataSource;
}
The model is a TTURLRequestModel
, so when the response is returned from the model, I set the dataSource's items and sections in my TTTableViewController
like so:
- (void)modelDidFinishLoad:(id<TTModel>)model {
((TTSectionedDataSource *)self.dataSource).items = ((LogsModel *)model).items;
((TTSectionedDataSource *)self.dataSource).sections = ((LogsModel *)model).sections;
[super modelDidFinishLoad:model];
}
This issue came up when I switched from using hard-coded data in my model to actually making a request to the web service. What am I doing wrong? Am I creating the model incorrectly? Or setting the items & sections on the dataSource in the wrong place? Any thoughts or comments are welcome and appreciated. Thanks!
I would recommend taking a look at the three20's twitter demo app (TTTwitter). Three20 has a simplified way on separating the models / data source and tables.
The controller should only create the datasource, without "knowing" about the items and sections:
///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)createModel {
self.dataSource = [[[TTTwitterSearchFeedDataSource alloc]
initWithSearchQuery:@"three20"] autorelease];
}
Finally found the reason for this. In my model class (LogsModel for the code above), I implemented the - (BOOL)isLoaded
method when I was using hard-coded data. When I switched to making requests to the web service, my implementation of isLoaded
happened to return NO all the time, so the TTTableViewController wasn't showing my data. I removed my implementation of - (BOOL)isLoaded
, and the problem was solved.
精彩评论