Slow Scrolling UITableView

Edit ----- I made the same code at the English scroll speed of the record, as usual, it works quickly and normally, but when I get the Arabic scroll of the data, it happens slowly. is this a problem with arab data ???

I have records around 100, and my table scrolling is very slow. can someone tell me what is wrong with this code and why iam slow scroll?

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

    GreetingAppDelegate *appdelegate = (GreetingAppDelegate *)[[UIApplication sharedApplication]delegate];
    DBSetter *product = (DBSetter *)[appdelegate.myrecords objectAtIndex:indexPath.row];    

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        cell.textLabel.font=[UIFont fontWithName:@"Arial" size:16.0];
    }


    CGRect a=CGRectMake(8, 0, 307, 59);
    UIImageView *aImg=[[UIImageView alloc] initWithFrame:a];
    UIImageView *bImg=[[UIImageView alloc] initWithFrame:a];

    //if(indexPath.row%2==0)
    aImg.image=[UIImage imageNamed:@"cell-arrow.png"];


    //else {
    //  aImg.image=[UIImage imageNamed:@"CellHighlight.png"];   
    //}



    bImg.image=[UIImage imageNamed:@"cell-arrow-h.png"];
    [aImg setContentMode:UIViewContentModeScaleToFill];
    [bImg setContentMode:UIViewContentModeScaleToFill];
    cell.backgroundView=aImg;
    cell.selectedBackgroundView=bImg;
    [aImg release];
    [bImg release];


    NSString *tempStr=[NSString stringWithFormat:@"%@",product.tempdesc];

    //int stringlength=[tempStr length];
    //[[tempStr stringByReplacingOccurrencesOfString:@"<Dear User>" withString:@" "] substringWithRange:NSMakeRange(0, 20)];

    //if (stringlength >20) {
    //cell.textLabel.text = [NSString stringWithFormat:@"%@...", [[tempStr stringByReplacingOccurrencesOfString:@"<Dear user>" withString:@""] substringWithRange:NSMakeRange(0, 30)]];
    //}
    //else {
        cell.textLabel.text = tempStr;
    //}


    if(appdelegate.lang==2) 

    {
        [cell setTextAlignment:UITextAlignmentRight];
aImg.transform = CGAffineTransformMakeScale(-1, 1);
        bImg.transform = CGAffineTransformMakeScale(-1, 1);
    }

    return cell;
}
+3
source share
4 answers

Thanks to everyone for your answers ... I just figured it out myself. I just use length and range to make it work. The code I used is the following, for someone who might have the same problem.

NSString *tempStr=[NSString stringWithFormat:@"%@",product.tempdesc];

    int stringlength=[tempStr length];
    if (stringlength >20) {
    cell.textLabel.text = [NSString stringWithFormat:@"%@...", [[tempStr stringByReplacingOccurrencesOfString:@"<Dear user>" withString:@""] substringWithRange:NSMakeRange(0, 30)]];
    }
    else {
    cell.textLabel.text = tempStr;
    }
0
source

, imageView .

if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    cell.textLabel.font=[UIFont fontWithName:@"Arial" size:16.0];
    CGRect a=CGRectMake(8, 0, 307, 59);
    UIImageView *aImg=[[UIImageView alloc] initWithFrame:a];
    UIImageView *bImg=[[UIImageView alloc] initWithFrame:a];

    aImg.image=[UIImage imageNamed:@"cell-arrow.png"];

    bImg.image=[UIImage imageNamed:@"cell-arrow-h.png"];
    [aImg setContentMode:UIViewContentModeScaleToFill];
    [bImg setContentMode:UIViewContentModeScaleToFill];
    cell.backgroundView=aImg;
    cell.selectedBackgroundView=bImg;
    [aImg release];
    [bImg release];
}
+3

The first thing I see: you do not use recycling!

Do as much as possible in the block if (cell == nil). Avoid creating representations of images and other things like this every time an element scrolls.

The only meaningful code for the recycled cells that I see is a string cell.textLabel.text = tempStr;.

+2
source

Have you tried to create your own TableViewCell with this image as a background? You can change the background when you select a custom TableViewCell in the setSelected function.

+1
source

All Articles