我遇到了问题,我只能想象是一个非常简单的问题。我从一个UIViewController
加载UITableViewController
类叫做LocationViewController
:从代码加载UITableViewController
LocationViewController *lvc = [[LocationViewController alloc] init];
[self.navigationController pushViewController:lvc animated:true];
在这个类我已经实现以下3个方法:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 3;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CityCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.textLabel.text = @"Test";
return cell;
}
而且我收到以下错误:
UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
在使用StoryBoard在ViewControllers之间转换之前,我有过这个错误,这是因为CellIdentifier不是c orrect。我不知道我做错了什么。我试过用这个ViewController加载一个nib文件,但是会引发同样的错误。
只是可以肯定...你验证**这**的cellForRowAtIndexPath:实际上是被调用(并可能在返回之前记录'cell'的值)? – 2012-04-02 13:43:00