2013-02-08 95 views
0

在我的tableView表格中始終存在五行,當我點擊其中一行時,新的三行將出現在所點擊的行的下方。將具有自定義單元格的行插入到表格視圖中

如果前五行是默認的UITableViewCell ,,,我希望這三個單元格也來自另一個自定義單元格;所以主要的五個單元格將不同於次要的行(主單元格下面的三個單元格)。

這是我如何添加輔助行:

tableView委託didSelectRowAtIndexPath

NSInteger count = indexPath.row + 1; 
NSMutableArray *newRows = [NSMutableArray array];// 

    self.expandedIndex = indexPath.row + 1; 
    self.tableExpanded = YES; 

    for(int i = 0; i < [self.numbers count]; i++) 
    { 
     NSIndexPath *path = [NSIndexPath indexPathForRow:count inSection:0]; 
     [newRows addObject:path]; 
     [self.myArray insertObject:[self.numbers objectAtIndex:i] atIndex:count]; 
     count++; 
    } 

    [tableView insertRowsAtIndexPaths:newRows withRowAnimation:UITableViewRowAnimationTop]; 

加入該行,但我想他們是從,我想創建自定義單元格,,,任何想法

回答

0

這是我會做的。我會讓newRows屬性,然後在didSelectRowAt...結束時我會調用表刷新。然後在我的cellForRowAtIndexPath檢查,以查看特定的indexPath是newRows,如果是使用不同的單元格樣式:

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

    UITableViewCell *cell; 

    if ([self.newRows contains:indexPath]) { 
     // create custom cell 
    } else { 
     // create normal cell 
    } 

    return cell; 
} 

如果這沒有任何意義,讓我知道,我能不能詳細。

另外請注意,你將有一些有趣的邊緣案件處理。例如,如果用戶點擊第3個單元格並且新單元格被插入到第4-6行中,並且他們稍後單擊第2單元格,在第3-5行中添加新的單元格,則之前的4-6個單元格現在將處於第7-9行。我不知道你是如何構建你的應用程序,所以這可能不是一個問題(如可能在五個單元之一可以一次添加子單元),但只是意識到這是一種可能性。

相關問題