ios - 滚动时在UITableView中重复数据

标签 ios objective-c cocoa-touch uitableview

我使用波纹管代码在TableView上显示数据,但是在滚动,重复数据和其他数据时会丢失。

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

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [FileCompletedArray count];

}

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

    static NSString *CellIdentifier = @"CellIdentifier";

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

        UILabel *FileNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 100, 30)];
        FileNameLabel.backgroundColor = [UIColor clearColor];
        FileNameLabel.font = [UIFont fontWithName:@"Helvetica" size:16];
        FileNameLabel.font = [UIFont boldSystemFontOfSize:16];
        FileNameLabel.textColor = [UIColor blackColor];
        NSLog(@"Reseversed TEMP array %@",FileCompletedArray);
        FileNameLabel.text =[FileCompletedArray objectAtIndex:indexPath.row];
        [cell.contentView addSubview: FileNameLabel];
        [FileNameLabel release];



    }
        return cell;
}

你有什么解决办法?提前致谢

最佳答案

使用不同的单元格标识符

例如像波纹管...

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

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

    UITableViewCell *cell = [_tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        /// write your code here..
    }
}

像下面一样设置nil
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    //static NSString *CellIdentifier = @"CellIdentifier";    

    UITableViewCell *cell = [_tableView dequeueReusableCellWithIdentifier:nil];
    if (cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil] autorelease];
        /// write your code here..
    }
}

关于ios - 滚动时在UITableView中重复数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17467580/

相关文章:

android - GIS:在 Google Map 的数据层上使用 .tif

ios - 在 SWIFT 中使用 FMDB 访问外部数据库

ios - 如何在 iOS 8 map 上同时显示当前位置和所有注释图钉

objective-c - NSDictionary 选择器错误 NSString 带空格

objective-c - Swift 到 Objective-C header 不包含 Swift 类

objective-c - 使用多个条件搜索字典数组

objective-c - Objective C iOS 开发中的数学方程式

iPhone PList 和 NSDate 问题

iphone - 在iPhone邮件应用程序上绘制蓝色 "unread dot"

ios - 是否可以在不复制所有代码的情况下复制 iOS 应用程序?