【发布时间】:2011-05-22 13:16:25
【问题描述】:
我在将数据加载到 UITableView 时遇到问题。
我的实现如下:
@interface FirstViewController : UINavigationController <UIActionSheetDelegate, UITableViewDelegate> {
UITableViewController *tableViewController;
UITableView *table;
}
@end
而viewDidLoad方法是:
- (void)viewDidLoad {
[super viewDidLoad];
tableViewController = [[UITableViewController alloc] init];
table = [[UITableView alloc] init];
tableViewController.tableView = table;
[tableViewController.tableView setDelegate:self];
self.newsList = [NSMutableArray array];
tableViewController.tableView.rowHeight = 130.0;
[self addObserver:self forKeyPath:@"newsList" options:0 context:NULL];
[self pushViewController:tableViewController animated:NO];
}
我不明白出了什么问题。可能是因为我正在添加观察者而无法加载数据?
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context
{
[tableViewController.tableView reloadData];
}
感谢您的建议!
【问题讨论】:
-
我们可能需要更多关于您从哪里调用它的详细信息,但我认为从视图尚不可见的导航控制器调用
-pushViewController:animated:存在问题。 (viewDidLoad 发生在视图可见之前)。 -
这个表单是从 UITabBarController 调用的。我已将其分配给 TabView 之一
标签: iphone cocoa-touch ios ios4