Ios 表视图未填充对象
我有一个带有对象数组的tableview,但当我运行它时。什么也没出现。我对xcode相当陌生,但我不确定代码中的错误是什么。有人能帮我吗?像这样更改代码您的代码将运行Ios 表视图未填充对象,ios,arrays,uitableview,Ios,Arrays,Uitableview,我有一个带有对象数组的tableview,但当我运行它时。什么也没出现。我对xcode相当陌生,但我不确定代码中的错误是什么。有人能帮我吗?像这样更改代码您的代码将运行 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"GenusNameCell";
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"GenusNameCell";
GenusNameCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[GenusNameCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"GenusNameCell"];
cell.GenusNameLabel.text = [genusName objectAtIndex:indexPath.row];
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
}
return cell;
}
geniusname
是存储人名的NSString。如果从未调用CellForRowatineIndexPath回调,则可能是:
- 您没有设置tableview的数据源李>
- 您没有实现numberOfSectionsInTableView:和/或tableView:numberOfRowsInSection:回调
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"GenusNameCell";
GenusNameCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[GenusNameCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"GenusNameCell"];
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
}
cell.GenusNameLabel.text = [[genusName objectAtIndex:indexPath.row] geniusname];
return cell;
}
您是否初始化了数组
genusName
?GenusNameCell:来自xib?代码看起来不错。数据一定是坏的。请验证。是的,我做了genusName=[[NSMutableArray alloc]init];[genusName addObject:@“冷杉”];你在哪里做的?那也不行你怎么能把你的字符串保存在数组上,。。你能分享你的代码吗?事实上,你将所有数据添加到genusName数组中,。。那么只有你才能从中找回,。。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"GenusNameCell";
GenusNameCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[GenusNameCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"GenusNameCell"];
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
}
cell.GenusNameLabel.text = [genusName objectAtIndex:indexPath.row];
return cell;
}