Objective c 目标C:在UITableView中创建2个自定义单元格

Objective c 目标C:在UITableView中创建2个自定义单元格,objective-c,uitableview,custom-cell,Objective C,Uitableview,Custom Cell,我有一个tableview,其中包含: -2个自定义单元格:红细胞和蓝细胞 -2个按钮:屏幕底部的红色按钮和蓝色按钮 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { if(indexPath.section == 0) { RedTableViewCell *redCell = (RedTable

我有一个tableview,其中包含:

-2个自定义单元格:红细胞蓝细胞

-2个按钮:屏幕底部的红色按钮和蓝色按钮

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

        if(indexPath.section == 0) {
            RedTableViewCell *redCell = (RedTableViewCell *)[tableView dequeueReusableCellWithIdentifier:BlockListTableViewCellIdentifier forIndexPath:indexPath];
            Red *red = (Red *)[self.reds objectAtIndex:indexPath.row];

            return redCell;
        }
        else
        {
            BlueTableViewCell *blueCell = (BlueTableViewCell *)[tableView dequeueReusableCellWithIdentifier:RestBlockTableViewCellIdentifier forIndexPath:indexPath];
            Blue *blue = [self.blues objectAtIndex:indexPath.row];

            return blueCell;
        }

        return nil;
    }

我希望在单击添加的红按钮时,单击添加的蓝按钮


p/S:我不想改变背景颜色,我想要两个不同的单元格。

我根据您不清楚的问题假设如下

红细胞包含一个红色按钮,当您单击此红色按钮时,您希望添加一个新的红细胞。与蓝色细胞类似

解决方案:

内部,红色(或蓝色)按钮动作

  • 在self.reds(或self.blues)数组中添加新条目
  • 重新加载tableview

  • 另外,请检查,numberofRowsinSection应返回self.reds.count作为第0部分,self.blues.count作为其他部分。

    如果我的问题值得否决票,我想知道为什么我可以改进自己。谢谢。您的问题不清楚,并且没有显示您的任何尝试。(附:我没有否决投票,但这可能是原因)@Larme谢谢你。我会编辑它。