簡體   English   中英

Objective-C:在UITableView中創建2個自定義單元格

[英]Objective-C : Create 2 custom cells in UITableView

我有一個tableview包含:

-2個自定義單元格: redCellblueCell

-2按鈕:屏幕底部的redButtonblueButton

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

我的TableView

我希望當我單擊redButton =添加redCell時 ,單擊blueButton =添加blueCell

P / S:我不想更改背景顏色,我想要2個不同的單元格。

我從您不清楚的問題中假設以下內容。

紅色單元格包含一個紅色按鈕,並且當您單擊該紅色按鈕時,您希望添加一個新的紅色單元格。 與藍色單元格類似。

解:

內部,紅色(或藍色)按鈕動作,

  1. 在您的self.reds(或self.blues)數組中添加新條目
  2. 重新加載tableview

另外,檢查numberofRowsinSection應該為第0節返回self.reds.count,為其他節返回self.blues.count。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM