我有一個可以在兩種模式下工作的tableview:只讀和讀寫。在只讀模式下,表格只包含4個單元,處於讀寫模式 - 8個單元。爲了這2種模式之間的過境我有按鈕,實現行動:插入/刪除單元格後,單元格不在UITableView中呈現
...
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細胞)了,所以它彈了起來。在此之後,輕按按鈕以變換成MODE2導致的情況時,不renderred細胞中的一種:
before transition:
after transition:
我的調查表明,由於某些原因在UITableView的最後layoutSubviews調用之後,這個單元格的alpha = 0。
我被卡住了,我不知道發生了什麼,所以任何幫助將非常感激。
UPDATE: 這是我的cellForRowAtIndexPath方法: - (的UITableViewCell *)的tableView:(UITableView的*)的tableView的cellForRowAtIndexPath:(NSIndexPath *)的cellForRowAtIndexPath { IDataSourceElement項= [[自收集] getDataSourceElementAtIndex:cellForRowAtIndexPath.row ]。
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設置爲零,所以它永遠不會從此方法返回。而且......它幫助了!我不知道爲什麼,並且真的想知道答案?
當alpha設置爲0時,它隱藏/不可見...將alpha設置爲1 ..以使其再次可見。 –
:)謝謝,但我想知道它爲什麼設置爲0在第一個地方 – iKiR