[英]Objective-C : Create 2 custom cells in UITableView
我有一個tableview包含:
-2個自定義單元格: redCell和blueCell
-2按鈕:屏幕底部的redButton和blueButton 。
-(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;
}
我希望當我單擊redButton =添加redCell時 ,單擊blueButton =添加blueCell 。
P / S:我不想更改背景顏色,我想要2個不同的單元格。
我從您不清楚的問題中假設以下內容。
紅色單元格包含一個紅色按鈕,並且當您單擊該紅色按鈕時,您希望添加一個新的紅色單元格。 與藍色單元格類似。
解:
內部,紅色(或藍色)按鈕動作,
另外,檢查numberofRowsinSection應該為第0節返回self.reds.count,為其他節返回self.blues.count。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.