2012-07-22 29 views
0

在我的UITableView中,我有一些自定義單元格,然後是需要重複10次的自定義單元格,每個UILabel都有一個不同的值。一切都呈現良好,直到我嘗試重複使用我最後一次自定義單元多次。會發生什麼是最後一個單元格繪製正確,但前9顯示爲空白,單元格之間沒有分割。重複的自定義UITableViewCell只繪製最後一個單元格

這裏是我的代碼:

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

static NSString *CellIdentifier = @"Cell"; 

UITableViewCell *cell = nil; 

if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
} 

// Configure the cell... 
switch (indexPath.row) { 
    case 0: 
     cell = nameCell; 
     break; 
    case 1: 
     cell = globalSettingsCell; 
     break; 
    case 2: 
     cell = queueTypeCell; 
     break; 
    case 3: 
     cell = starMinCell; 
     break; 
    case 4: 
     cell = lengthMaxCell; 
     break; 
} 

if (indexPath.row > 4) { 
    cell = genreCell; 
    genreLabel.text = [genres objectAtIndex:(indexPath.row - 5)]; 
} 

return cell; 

}

回答

0

不能使用多個indexPaths simultanously一個單元(genreCell)。

0

您只有一個標識符,但多於一個不同的單元格?我認爲你不知道如何重用Cells正確。

嘗試這樣的事情...

static NSString *CellIdentifier_1 = @"Cell_1"; 
static NSString *CellIdentifier_2 = @"Cell_2"; 
//... 
UITableViewCell *cell = nil; 
switch (indexPath.row) { 
    case 0: 
     cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier_1]; 
     if (cell == nil) { 
      cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier_1] autorelease]; 
     } 
     break; 
    case 1: 
     cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier_2]; 
     if (cell == nil) { 
      cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier_2] autorelease]; 
     } 
     break; 
} 
相關問題