2011-08-01 35 views
0

我一直有一個奇怪的問題,我以前從未見過表格單元格。當我滾動桌子時,他們互相流血。例如,現在我在第一部分有一個單元格,其中有「Device」和第二部分中的一組單元格,分別表示「Hi」和第三部分中的幾個空白單元格。當我滾動時,有時候「設備」被寫在「Hi」的頂部(所以兩個標籤都可見但是彼此重疊(它們具有清晰的背景色),有時候「Hi」會被寫入第三部分的單元格中。 。試圖找出什麼是錯的,但似乎沒有任何工作表格單元彼此流血

這裏是我的表視圖控制器的相關章節:

- (id)initWithDeviceCoordinator:(DeviceCoordinator*)dev_con 
{ 
    self = [super initWithStyle:UITableViewStyleGrouped]; 
    if (self) { 
     device_coordinator = dev_con; 
    } 
    return self; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
} 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return 4; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    // Return the number of rows in the section. 
    if (section == 0 || section == 3) return 1; 
    else if (section == 1) return 8; 
    else if (section == 2) return 2; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 

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

    if (indexPath.section == 0) cell.textLabel.text = [device_coordinator getDeviceName]; 
    else if (indexPath.section == 1) 
    { 
     if (indexPath.row == [[device_coordinator getChannelList] count]) 
     { 
      cell.textLabel.text = @"Add new channel"; 
      return cell; 
     } 
     cell.textLabel.text = @"HI"; 
     return cell; 
    } 
    return cell; 
} 

所有的類中的其他功能的XCode默認

回答

0

我發現了這個問題。正是有了這條線:

static NSString *CellIdentifier = @"Cell"; 

將其更改爲這個固定的一切:

NSString *CellIdentifier = [NSString stringWithFormat:@"Cell %d_%d",indexPath.section,indexPath.row]; 
+1

這不是問題,也沒有解決。 – InsertWittyName

1

你應該設置cell.textLabel.text = nil開始,否則當單元格被重用時你會看到你的文本在錯誤的地方(就像你一樣身份證你看到嗨,它不應該出現)。至於重疊的標籤,我不認爲你粘貼的代碼可能會導致這種情況。你在使用自定義單元嗎?