简体   繁体   English

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

[英]Scrolling issue in iPhone app running on 3GS

The below method is causing the Scrolling problem when i run it on my iPhone 3S. 当我在iPhone 3S上运行时,以下方法导致滚动问题。 I know we can increase the performance of Scrolling but don't know how to do it even after searching a lot on the net and tried several things. 我知道我们可以提高滚动的性能,但即使在网上搜索了很多东西并尝试了几件事之后也不知道怎么做。

I have come across making cells opaque and/or making Table views as Sub views to greatly increase the Scrolling performance if someone can modify the below code or just point what needs to change in the below code. 我遇到过使单元格不透明和/或使表视图成为子视图,以便在有人可以修改下面的代码或只是指出需要在下面的代码中更改的内容时大大提高滚动性能。 My code is below. 我的代码如下。

// 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] ?? [cellIdentifier发布] ?? You don't release statics !! 你不释放静电!! Your cell reuse is probably failing because of it. 您的单元重用可能因此失败。

Also there is no autorelease on UITableViewCell allocation. 在UITableViewCell分配上也没有自动释放。 This should be causing lots of leaks and ultimately slow down / crash the app as well. 这应该会导致大量泄漏并最终减慢/崩溃应用程序。

This is a deadly combination of leak + cell reuse failure 这是泄漏+细胞再利用失败的致命组合

Hope this helps 希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM