Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.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 UITableView单元具有三种不同单元设计的不同标识符_Ios_Objective C_Iphone_Uitableview - Fatal编程技术网

Ios UITableView单元具有三种不同单元设计的不同标识符

Ios UITableView单元具有三种不同单元设计的不同标识符,ios,objective-c,iphone,uitableview,Ios,Objective C,Iphone,Uitableview,我每次只得到一个细胞,它是第一个细胞 它不需要if条件语句。 提前感谢您的回复更改您使用=将字符串与isEqualToString: 例如: 改变 到 尝试使用开关条件,否则,如果>P>我认为如果你重新考虑整个逻辑,那就更好了。 我也会这样做 if([type isEqualToString:CellIdentifier]) 创建UITableViewCell类“CustomCell”。 在“CustomCell.xib”中创建三个UITableViewCell。对于每种类型的每个单元格,整个

我每次只得到一个细胞,它是第一个细胞

它不需要if条件语句。
提前感谢您的回复

更改您使用
=
将字符串与
isEqualToString:

例如: 改变


尝试使用开关条件,否则,如果

>P>我认为如果你重新考虑整个逻辑,那就更好了。 我也会这样做

if([type isEqualToString:CellIdentifier])
创建UITableViewCell类“CustomCell”。 在“CustomCell.xib”中创建三个UITableViewCell。对于每种类型的每个单元格,整个xib将具有标识符“CustomCellid”
然后,上面的代码将为您提供所需的结果。请尝试使用isEqualToString:method比较两个字符串。为什么将UITableViewCell、mycell置于条件之外?一个好的做法是将所有类型的单元格放在其中一个条件中,模式应为“if”、“elseif”,最后为“else”。这样,如果没有匹配项,您的方法将返回else语句中的单元格。尝试在每个循环中放置一个断点,以查看对于不同的类型,您的代码是否正在进入相应的条件块。在故事板中,您的单元的单元标识符是什么?这里的日志说明了什么:
NSLog(@“types===%@”,type)?谢谢,但输出是相同的,我想根据来自服务器的类型显示每个单元格。
if (type == CellIdentifier)
if([type isEqualToString:CellIdentifier])
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *type = [[myaray objectAtIndex:indexPath.row]objectForKey:@"type"];
    myCell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:@"CustomCellid" ];
    if(myCell==nil)
    {
        NSArray *arr= [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];

        if(types isEqualToString:@"reviews")
        {
           myCell=[arr objectAtIndex:0];    
        }
        else if(types isEqualToString:@"recipes")
        {
           myCell=[arr objectAtIndex:1];
        }
        else if(types isEqualToString:@"easy_tips")
        {
           myCell=[arr objectAtIndex:2];
        }

   }


return myCell;

}