簡體   English   中英

UITableView-通過點擊現有單元格來插入新行

[英]UITableView - insert new row by tapping on existing cell

我將UITableView與原型單元一起使用,並且希望最上面的單元是“加法”單元:當用戶點擊該單元時,將執行segue。 由於UITableView是動態生成的(最上面的一個除外)並且單元正在重用,所以我有兩個問題:

1-是否可以制造一個static單元格,而其他所有單元格仍為原型單元格?

2-如果沒有,如何實施此解決方案? 我認為,必須在

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

但我不知道,這種方法正確嗎? 我是否正確,要實現此自定義單元,我需要檢查indexPath.row = 0並用自定義替換所需的單元,同時以編程方式將所有單元向下移動一排嗎?

Yiu可以在“ Tap of Your”單元中進行操作,您可以創建兩個不同的單元,一個為原型單元,另一個為您的詳細信息

在你的

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        AdderCell *cell = (AdderCell*)[tableView dequeueReusableCellWithIdentifier:@"AdderCell" forIndexPath:indexPath];
     } else {
       CustomCell *cell = (CustomCell*)[tableView dequeueReusableCellWithIdentifier:@"CustomCell" forIndexPath:indexPath];
     }
}

在您的Adder單元中點擊

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
                // add data to your row array and reload the tableRow
             } else {
               // do your tap action
             }
     }

暫無
暫無

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

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