Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/95.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 我想创建CustomCell,但它给出了一些错误,如何解决它??错误描述如下_Ios_Ipad_Uitableview - Fatal编程技术网

Ios 我想创建CustomCell,但它给出了一些错误,如何解决它??错误描述如下

Ios 我想创建CustomCell,但它给出了一些错误,如何解决它??错误描述如下,ios,ipad,uitableview,Ios,Ipad,Uitableview,} 返回空值 以上是我的方法,它给出了以下错误: 这里 由于未捕获异常而终止应用程序 “NSInternalInconsistenceException”,原因:“UITableView数据源 必须从tableView返回单元格:cellForRowAtIndexPath:' 您没有在if(cell==nil)位中分配新的单元格。您需要分配一个新的UITableViewCell返回 取消排队的工作方式是: 向表格视图询问具有CellIdentifier 如果单元格为零,则使用CellIdenti

}

返回空值

以上是我的方法,它给出了以下错误: 这里

由于未捕获异常而终止应用程序 “NSInternalInconsistenceException”,原因:“UITableView数据源 必须从tableView返回单元格:cellForRowAtIndexPath:'


您没有在if
(cell==nil)
位中分配新的单元格。您需要分配一个新的
UITableViewCell
返回

取消排队的工作方式是:

  • 向表格视图询问具有
    CellIdentifier

  • 如果单元格为零,则使用
    CellIdentifier
    分配一个新单元格,以便将来可以重复使用

  • 所以你可以这样做:

     NSLog([cell Description]);
    

    希望这对您有所帮助。

    您没有在if
    (cell==nil)
    位中分配新的单元格。您需要分配一个新的
    UITableViewCell
    返回

    取消排队的工作方式是:

  • 向表格视图询问具有
    CellIdentifier

  • 如果单元格为零,则使用
    CellIdentifier
    分配一个新单元格,以便将来可以重复使用

  • 所以你可以这样做:

     NSLog([cell Description]);
    
    希望这有助于改变这种状况:

    static NSString *CellIdentifier = @"CustomCell";
    //Ask for a cell with the cell identifier
    CustomCell *cell = (CustomCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    //If the cell is nil
    if (cell == nil) 
    {
    //Allocate a new cell with the identifier
        cell = [[CustomCell alloc] init];//put your actual init method here
    }
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) 
    {
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    cell.cellDate.text=@"date";
    cell.cellDescription.text =@"Description";
    cell.cellImageview.image = [UIImage imageNamed:@"sample.png"];
    cell.cellTitle.text = @"Title";
    NSLog([cell Description]);
    return cell;
    
    致:

    更改此项:

    static NSString *CellIdentifier = @"CustomCell";
    //Ask for a cell with the cell identifier
    CustomCell *cell = (CustomCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    //If the cell is nil
    if (cell == nil) 
    {
    //Allocate a new cell with the identifier
        cell = [[CustomCell alloc] init];//put your actual init method here
    }
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) 
    {
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    cell.cellDate.text=@"date";
    cell.cellDescription.text =@"Description";
    cell.cellImageview.image = [UIImage imageNamed:@"sample.png"];
    cell.cellTitle.text = @"Title";
    NSLog([cell Description]);
    return cell;
    
    致:

    别忘了在“编译源代码”选项卡中添加customcell的.m文件



    别忘了在“编译源代码”选项卡中添加customcell的.m文件

    您确实显示了完全相同的内容,只是您添加了一个额外的检查来检查
    cell==nil
    ,它始终是nillCustomCell*cell=nil;使每次在表视图中创建一个新单元格时,它不会重用单元格。这将始终返回nil-您在某个时候需要使用重用标识符分配单元格。tableview收集这些数据并尽可能重复使用它们,但是如果它需要一个新的单元格,那么您需要分配它。它将如何初始化?从未创建新单元格。您不需要更改
    CustomCell*单元格=(CustomCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]行。这是正确的。您需要做的是创建一个新的单元格,如果该单元格为nil,即某个单元格不可重用…您确实显示了完全相同的内容,只是您添加了一个额外的检查,以检查
    单元格==nil
    ,该检查始终为nillCustomCell*cell=nil;使每次在表视图中创建一个新单元格时,它不会重用单元格。这将始终返回nil-您在某个时候需要使用重用标识符分配单元格。tableview收集这些数据并尽可能重复使用它们,但是如果它需要一个新的单元格,那么您需要分配它。它将如何初始化?从未创建新单元格。您不需要更改
    CustomCell*单元格=(CustomCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]行。这是正确的。您需要做的是创建一个新单元,如果该单元为nil,即某个单元不可重用…如果(cell==nil){}@vitality显示的内容正确,请在内部分配您的自定义单元。底线是您需要初始化一个新单元。因此,在
    (cell==nil)
    之后,只需插入以下行:
    cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]在内部分配您的自定义单元格(cell==nil){}。底线是您需要初始化一个新单元。因此,在
    (cell==nil)
    之后,只需插入以下行:
    cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]在实现新代码后获取此错误:架构i386的未定义符号:“\u OBJC\u CLASS\u$\ u CustomCell”,引用自MasterViewController中的:OBJC CLASS ref。o ld:未找到架构i386的符号clang:错误:链接器命令失败,退出代码为1(使用-v查看调用)如果执行此操作,则无法将CustomCell.xib加载到tableview单元格中。在执行新代码:架构i386的未定义符号:“\u OBJC\u CLASS\u$\ u CustomCell”,引用自:MasterViewController中的OBJC CLASS ref.o ld:symbol后,您是否意识到此错误找不到架构i386的clang:错误:链接器命令失败,退出代码为1(使用-v查看调用),无法将CustomCell.xib加载到tableview单元格中您知道吗
    
    CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier: CellIdentifier];
    
    if (cell == nil) 
    {
        cell = [[[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
              cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        }
    }
    
    enter code here// Customize the appearance of table view cell
       - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:  (NSIndexPath *)indexPath
    {
       static NSString *CellIdentifier = @"CustomCell";
       CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:  CellIdentifier];
    
    if (cell == nil)
    {
         cell = [[[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    
    }
    
    cell.cellDate.text=@"date";
    cell.cellDescription.text =@"Description";
    cell.cellImageview.image = [UIImage imageNamed:@"sample.png"];
    cell.cellTitle.text = @"Title";
    return cell;
    
    
    }