iphone - UITableView滚动问题

问题描述:

我在我的应用程序中创建了一个TableView,其中有5个部分。iphone - UITableView滚动问题

1-4节只包含一行分钟,第5节包含5行。

一切正常,直到我从屏幕上滚动TableView。在我的第一部分和行(单元格)中,我将accessoryView设置为带有一些文本的UILabel。

每隔一个单元格都有披露按钮作为accessoryType。

当我滚动tableView我在第一个单元格中的文本以某种方式出现在最后一个单元格!?

我已经通过向数组添加NSString来设置我的数据,然后将它们作为字典添加到NSMutableArray中。

,这里是我的手机设置:

- (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]; 
    } 

    // UISwitch *aUISwitch = [[[UISwitch alloc]initWithFrame:CGRectZero]autorelease]; 

    // Configure the cell. 

    NSDictionary *dictionary = [listOfSettings objectAtIndex:indexPath.section]; 
    NSArray *array = [dictionary objectForKey:@"Settings"]; 
    NSString *cellValue = [array objectAtIndex:indexPath.row]; 
    cell.textLabel.text = cellValue; 

    if([cellValue isEqualToString:@"Status"]){ 
     UILabel *viewLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 20)]; 
     [viewLabel setText:@"Connected"]; 
     cell.accessoryView = viewLabel; 
     [viewLabel release]; 

    } 
    else{ 
    cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton; 
    } 
    return cell; 
} 

我知道细胞被删除/删除,当他们去关闭屏幕,所以我想这有什么关系呢?处理细胞脱离屏幕并重新出现的建议做法是什么?

只是在快速浏览...在else语句中,不仅需要设置cell.accessoryType,还需要设置cell.accessoryView = nil;

accesoryView仍然存在,因为细胞被回收。

+0

25分给你! :) 非常感谢! – 2011-04-29 16:11:20