2013-06-03 34 views
0

我已經stucked這個問題了幾天,我已經調試了很多次,並且不能找出什麼地方出了錯。 我有一個UITableView有三個部分。我想添加按鈕作爲accessoryView和UILabel作爲detailText到第二部分。 查看第一次加載時,它看起來沒問題。 enter image description here排查:以編程方式添加到accessoryView的UITableViewCell中搞砸

但滾動後,它就會變成enter image description here

夫婦卷軸後,凍結(不崩潰)。 以下是我的代碼,任何意見將不勝感激。

#pragma mark - Table view data source 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    // Return the number of sections. 
    return 3; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    if (section==0) { 
     return self.status.count; 
    } 
    else if (section==1) 
     return self.overrideCtrl.count; 
    else 
     return self.levelStatus.count; 
    // Return the number of rows in the section. 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"MenuCell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 
    NSLog(@"section %@",indexPath); 
    if (indexPath.section == 0) { 
     cell.textLabel.text = [self.status objectAtIndex:indexPath.row]; 
     NSLog(@"Status %@",cell.textLabel.text); 
    } 
    else if (indexPath.section == 1) { 
     cell.textLabel.text = [self.overrideCtrl objectAtIndex:indexPath.row]; 
     cell.detailTextLabel.text =[NSString stringWithFormat:@"00:%02d",[[self.timeLeftArray objectAtIndex:indexPath.row] intValue]];//[[self.timeLeftArray objectAtIndex:indexPath.row] stringValue]; 
     cell.accessoryView=[self.checkButtonArray objectAtIndex:indexPath.row]; 
     NSLog(@"override %@",cell.textLabel.text); 

    }else{ 
     cell.textLabel.text = [self.levelStatus objectAtIndex:indexPath.row]; 
     NSLog(@"level %@",cell.textLabel.text); 

    } 
    return cell; 
} 

謝謝!

回答

0

這個問題討論了很多關於SO,這是因爲細胞的重用。您需要設置accessoryView的到UITableViewCellAccessoryNone你的其他部分,否則,這是用於部分人們可能會在另一部分中使用的細胞,而且還有其附屬視圖。

+0

謝謝你的信息。有用。我試圖尋找解決方案,但沒有用處,可能是因爲我使用了錯誤的關鍵字。 – user1491987

0

你只有1 CellIdentifier。你應該爲每個部分有不同的一個。

+0

我的tableview是動態的,我可以設置小區標識符,用於通過碼每個部分? – user1491987

相關問題