1

読み取り専用と読み書きの 2 つのモードで動作するテーブルビューがあります。読み取り専用モードでは、テーブルには 4 つのセルのみが含まれ、読み取り/書き込みモードでは 8 つのセルが含まれます。これら 2 つのモード間を遷移するために、アクションが実装されたボタンがあります。

...
NSArray* cellIndexesInCurrentMode = [self cellIndexesInMode:Mode1];
NSArray* cellIndexInNewMode = [self cellIndexesInMode:Mode2];

[self.tableView beginUpdates];
[self.tableView insertRowsAtIndexPaths: cellIndexInNewMode withRowAnimation:UITableViewRowAnimationFade];
[self.tableView deleteRowsAtIndexPaths:cellIndexesInCurrentMode withRowAnimation:UITableViewRowAnimationFade];
[self.tableView endUpdates];

読み取り/書き込み (8 セル) でテーブルを下にスクロールするまで、すべてが正常に機能するため、跳ね上がりました。その後、ボタンをタップしてモード 2 に遷移すると、セルの 1 つがレンダリングされない状況が発生します。

                 before transition:  

移行前:

                 after transition:

移行後:

私の調査では、何らかの理由で、UITableView での最後の layoutSubviews 呼び出しの後、このセルのアルファ = 0 が示されました。

何が起こっているのかわからないので、どんな助けでも大歓迎です。

更新: これが私の cellForRowAtIndexPath メソッドです: - (UITableViewCell*) tableView :(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)cellForRowAtIndexPath {

MyTableCell* cell = nil;

if ([item conformsToProtocol:@protocol(MyTableCellBuilder)]) {
    cell = [(MyTableCellBuilder)item tableView:tableView buildCellForIndexPath:cellForRowAtIndexPath];
} 

if (cell == nil) {
    Class cellClass = [self getCellClassForElement: item];

    NSString* reuseId = [cellClass description];

    cell = [tableView dequeueReusableCellWithIdentifier:reuseId];
    if (!cell) {
        cell = [[[cellClass alloc] initWithReuseIdentifier :reuseId] autorelease];
    }
}


[self fillCell:cell forTableView:tableView forIndexPath:cellForRowAtIndexPath];

return cell;

}

および MyTableCellBuilder buildCellForIndexPath: メソッドの実装

- (MyTableCell*) tableView :(UITableView*)tableView buildCellForIndexPath:(NSIndexPath*)buildCellForIndexPath {
    MyTableCell* cell = myTableCell;
    if ([cell isKindOfClass:[TextPropertyCell class]] == NO) {
        cell = (MyTableCell*)[tableView dequeueReusableCellWithIdentifier :[self cellReuseIdentifier]];
        if ([cell isKindOfClass:[MyTableCell class]] == NO) {
            cell = [[[MyTableCell alloc] initWithReuseIdentifier :[self cellReuseIdentifier]] autorelease];
        }
        [self prepareCell:cell];
    }

        //cell setup
        ...
    ...
    return cell;
}

私の考えは、UITableViewCellのインスタンスをキャッシュする際の問題であり、それが最善の方法ではないことはわかっていますが、とにかく私はそれを持っていました。キャッシュを削除しようとしたため、myTableCell を nil に設定したため、このメソッドから返されることはありません。と・・・助かりました!理由がわかりませんが、本当に答えを知りたいですか?

4

1 に答える 1

0

cellForRowAtIndexPath メソッドの実装を表示してください。ここで間違いを探す必要があると確信しています。

于 2013-01-03T12:51:36.160 に答える