【发布时间】:2023-03-29 02:20:01
【问题描述】:
我有一个表格视图控制器,FavoritesTableViewController,它有一个可变数组“citiesArray”。当按下城市按钮时,它会调用一个将对象添加到可变数组的方法。
[self.citiesArray addObject:@"New York"];
然后它会记录 self.citiesArray 的计数以及数组本身,并且似乎工作正常,这意味着它成功地将字符串“New York”添加到数组中。所以现在我有一个填充的可变数组并想用它填充表格视图。
这是我的代码,似乎不起作用。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cell"];
if (cell==nil) {
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
}
cell.textLabel.text=[self.citiesArray objectAtIndex:indexPath.row];
return cell;
}
之后我尝试重新加载我的表格视图,但仍然无法正常工作。关于问题是什么的任何想法? 谢谢
【问题讨论】:
-
别忘了检查表视图委托。
-
@pawan,委托与此问题无关。如果 OP 没有设置数据源可能是问题,但委托方法与获取数据无关。
-
@rdelmar 我的错,我错误地写了委托,它应该是数据源。
标签: ios objective-c arrays nsmutablearray uitableview