我有我目前出隊,像這樣3個自定義UITableViewCells一個UITableView:自定義的UITableViewCell不會離隊正確
if (indexPath.row == 0) {
static NSString *CellIdentifier = @"MyCell1";
MyCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[MyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
return cell;
}
if (indexPath.row == 1) {
static NSString *CellIdentifier = @"MyCell2";
MyCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[MyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
return cell;
}
if (indexPath.row == 2) {
static NSString *CellIdentifier = @"MyCell3";
MyCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[MyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
return cell;
}
我試圖這樣做多種方式,但問題是,即使我」 m仍然使用不同的標識符將它們全部排隊,當我滾動tableView時,有時候我的第一個單元出現在我的第三個單元的位置,反之亦然。似乎有一些奇怪的緩存正在進行。
有誰知道爲什麼?謝謝。
如果從刪除「靜態」什麼單元格標識符聲明? –
它沒有區別。在Apple文檔中,即使他們使用靜態NSString * CellIdentifier。 – VTS12
儘管您應該有三個不同的標識符變量,因爲您有三個不同的值。靜態只能初始化一次。你在哪裏看到這個代碼實際上是在細胞中放入任何信息,你在哪裏做的?你能提供一個問題的截圖嗎?真的只有三排嗎? – jrturton