Проблема с прокруткой в ​​приложении iPhone, работающем на 3GS - PullRequest
0 голосов
/ 16 декабря 2011

Приведенный ниже метод вызывает проблему с прокруткой, когда я запускаю его на своем iPhone 3S.Я знаю, что мы можем повысить производительность прокрутки, но не знаю, как это сделать, даже после того, как много поискал в сети и попробовал несколько вещей.

Я сталкивался с тем, чтобы сделать ячейки непрозрачными и / или сделать представления таблиц в качестве вложенных представлений, чтобы значительно повысить производительность прокрутки, если кто-то может изменить приведенный ниже код или просто указать, что необходимо изменить в приведенном ниже коде.Мой код ниже.

// 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;
}

1 Ответ

2 голосов
/ 17 декабря 2011

[выпуск cellIdentifier] ?? Вы не выпускаете статики! Возможно, из-за этого повторное использование вашей ячейки не удается.

Также нет автоматического выпуска при выделении UITableViewCell. Это должно вызывать множество утечек и, в конечном итоге, замедлять / завершать работу приложения.

Это смертельная комбинация утечки + сбоя повторного использования соты

Надеюсь, это поможет

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...