Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 表视图未填充对象_Ios_Arrays_Uitableview - Fatal编程技术网

Ios 表视图未填充对象

Ios 表视图未填充对象,ios,arrays,uitableview,Ios,Arrays,Uitableview,我有一个带有对象数组的tableview,但当我运行它时。什么也没出现。我对xcode相当陌生,但我不确定代码中的错误是什么。有人能帮我吗?像这样更改代码您的代码将运行 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"GenusNameCell";

我有一个带有对象数组的tableview,但当我运行它时。什么也没出现。我对xcode相当陌生,但我不确定代码中的错误是什么。有人能帮我吗?

像这样更改代码您的代码将运行

- (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:回调
如果将单元格出列,则需要在if分支外部设置文本,如下所示:

 - (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;
}