我的数据没有显示在我的 TTTableViewController 子类中。为什么不呢?
这是背景:我正在 TTTableViewController
中初始化并设置数据源,如下所示:
- (void)createModel {
TTSectionedDataSource *dataSource = [[[TTSectionedDataSource alloc] init] autorelease];
dataSource.model = [[[LogsModel alloc] init] autorelease];
self.dataSource = dataSource;
}
模型是 TTURLRequestModel
,因此当从模型返回响应时,我设置我的 TTTableViewController
中的数据源的项目和部分如下所示:
- (void)modelDidFinishLoad:(id<TTModel>)model {
((TTSectionedDataSource *)self.dataSource).items = ((LogsModel *)model).items;
((TTSectionedDataSource *)self.dataSource).sections = ((LogsModel *)model).sections;
[super modelDidFinishLoad:model];
}
当我从在模型中使用硬编码数据切换到实际向 Web 服务发出请求时,出现了此问题。我做错了什么?我是否错误地创建了模型?或设置项目&数据源上的部分放在错误的位置?欢迎并赞赏任何想法或评论。谢谢!
Here's the background: I'm initializing and setting the dataSource in my TTTableViewController
like so:
- (void)createModel {
TTSectionedDataSource *dataSource = [[[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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议您看一下 Three20 的 Twitter 演示应用程序 (TTTwitter)。 Three20 有一种分离模型/数据源和表的简化方法。
控制器应该只创建数据源,而不“了解”项目和部分:
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:
终于找到了这个原因。在我的模型类(上面代码的 LogsModel)中,当我使用硬编码数据时,我实现了
- (BOOL)isLoaded
方法。当我转而向 Web 服务发出请求时,我的isLoaded
实现始终返回 NO,因此 TTTableViewController 没有显示我的数据。我删除了- (BOOL)isLoaded
的实现,问题得到了解决。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 ofisLoaded
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.