3GS上运行的iPhone应用程序中的滚动问题

3GS上运行的iPhone应用程序中的滚动问题,iphone,xcode,uitableview,scroll,Iphone,Xcode,Uitableview,Scroll,当我在iPhone3S上运行它时,下面的方法导致了滚动问题。我知道我们可以提高滚动的性能,但即使在网上搜索了很多东西并尝试了一些方法,我也不知道该怎么做 如果有人可以修改下面的代码或只指出下面的代码中需要更改的内容,我会将单元格设置为不透明和/或将表视图设置为子视图,从而大大提高滚动性能。 我的代码如下 // cell is created for each row of track. - (UITableViewCell *)tableView:(UITableView *)tableView

当我在iPhone3S上运行它时,下面的方法导致了滚动问题。我知道我们可以提高滚动的性能,但即使在网上搜索了很多东西并尝试了一些方法,我也不知道该怎么做

如果有人可以修改下面的代码或只指出下面的代码中需要更改的内容,我会将单元格设置为不透明和/或将表视图设置为子视图,从而大大提高滚动性能。 我的代码如下

// cell is created for each row of track.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    NSLog(@"tableView cellForRowAtIndexPath");


    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    [CellIdentifier release];
    cell.accessoryView = nil;

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

     /** saving the data in Book structure.**/
     Book *aBook = [appDelegate.books objectAtIndex:indexPath.row];

     [cell.textLabel setText: aBook.name];

    // indexrow refers to each cell 
    temp =[appDelegate.tracklocation intValue];
    requesttemp =[appDelegate.requestlocation intValue];        

    // Coloring Code starts
    // indexPath starts from 0th cell that is why it is incremented by 1
    if(temp==(indexPath.row+1))
    { 
        NSLog(@"value of temp inside if is = %d",temp);
        NSLog(@"value of indexrow inside if is=%d",(indexPath.row+1));
        UIImageView *imageView1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"speaker.png"]];
        imageView1.backgroundColor = [ UIColor greenColor ];
        cell.contentView.backgroundColor = [ UIColor greenColor ];
        [cell.textLabel setBackgroundColor:[UIColor greenColor]];
        [cell.textLabel setTextColor:[UIColor blackColor]];
        [cell.detailTextLabel setBackgroundColor:[UIColor greenColor] ];
        [cell.detailTextLabel setTextColor:[UIColor blackColor] ];
        cell.accessoryView = imageView1;
        [imageView1 release];
    }
    else 
    {
        cell.contentView.backgroundColor = [ UIColor whiteColor ];
        [cell.textLabel setBackgroundColor:[UIColor whiteColor] ];
        [cell.textLabel setTextColor:[UIColor blackColor ]];
        [cell.detailTextLabel setBackgroundColor:[UIColor whiteColor]];
        [cell.detailTextLabel setTextColor:[UIColor grayColor] ];
    }

        while(requesttemp>temp)
        { 
            if (requesttemp==(indexPath.row+1))
            {
                if (colorflag==1)
                {
                    NSLog(@"value of request temp inside while is = %d",requesttemp);
                    NSLog(@"value of indexrow inside while is=%d",(indexPath.row+1));
                    cell.contentView.backgroundColor = [ UIColor blueColor ];
                    [cell.textLabel setBackgroundColor:[UIColor blueColor ]];
                    [cell.textLabel setTextColor:[UIColor whiteColor ]];
                    [cell.detailTextLabel setBackgroundColor:[UIColor blueColor] ];
                    [cell.detailTextLabel setTextColor:[UIColor whiteColor] ];
                }
            }
            requesttemp=requesttemp-1;
        }
    }    

    cell.detailTextLabel.text = abook.artist;

    cell.detailTextLabel.numberOfLines = 1;

     cell.detailTextLabel.lineBreakMode = UILineBreakModeWordWrap;
     NSLog(@"RootViewController cellForRowAtIndexPath %@ ",cell);

     return cell;
}

[cellIdentifier release]?? 你不能释放静力学!! 您的单元重用可能因此而失败

此外,UITableViewCell分配没有自动释放。这将导致大量泄漏,并最终导致应用程序速度减慢/崩溃

这是泄漏+单元重用失败的致命组合


希望这有帮助

iPhone3S不存在,它是3GS。[掌心]@maddy2011:你的录取率很低。谢谢你的更正。我已经相应地更改了代码,并将在我拿回设备后测试这个案例。代码中还要注意的一点是,我正在使用的
*abook
对象
Book*abook=[appDelegate.books objectAtIndex:indexPath.row]被声明为结构。与使用数组相比,这是否会导致获取记录并将其分配给单元格的速度变慢?这应该无关紧要。混合C不会导致任何性能问题,除非您在某处执行“传递值”。我觉得这行代码还可以。我更改了上面代码中的两行,滚动改进了lotOk。我更改了上面代码中的两行,滚动改进了很多<代码>[CellIdentifier release]
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle重用标识符:CellIdentifier]代码中的其他地方也存在其他内存泄漏,这导致了一些滚动问题,也可能是因为它一次又一次地对单元格着色,这可能导致滚动的平滑度缓慢。我需要检查一下。谢谢如果有人想对这一点发表意见,我将不胜感激。你提到的那一点确实奏效了。在我评论了
[CellIdentifier release]之后,它现在运行良好。谢谢