【发布时间】:2010-12-11 08:35:14
【问题描述】:
我在 Xcode 中使用基于导航的模板创建了一个应用程序。我还创建了一个实现 UITableViewDataSource 协议的类,并希望将它用于 RootViewController 中的 UITableView。
我尝试在 viewDidLoad 和各种初始化程序中设置 dataSource 属性,但我无法让它工作。
我该怎么做?
目前我正在做以下事情:
- (void)viewDidLoad {
[super viewDidLoad];
// The Navigation Controller uses this to display the title in the nav bar.
self.title = @"Names";
// Little button with the + sign on the right in the nav bar
self.navigationItem.rightBarButtonItem =
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(showAddNameScreen)];
// Set the data source and reload.
[self.tableView setDataSource:[DataAcceess sharedInstance]];
[self.tableView reloadData];
}
但表只是保持为空,并且永远不会调用数据源方法(numberOfRowsInSection 和 cellForRowAtIndexPath)
编辑:我的sharedInstance 有问题并返回零。从未调用过任何方法。
【问题讨论】:
-
您能否详细说明“无法正常工作”的含义?有编译错误吗?表格视图是否显示为空?它崩溃了吗?
-
表为空,UITableViewDataSource 方法中的断点没有被调用。
标签: iphone datasource uitableview