sticky uitableview

i'm having a problem with uitableview when i scroll it up and down many times it becomes sticky and all the containing view becomes sticky too.

here is my code:

- (UITableViewCell *)tableView:(UITableView *)tableView 
         cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

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

    cell.textLabel.text=[NSString stringWithFormat:@"         %@",
                            [SongsNames objectAtIndex:indexPath.row]];

    UIImageView *b=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 35, 34)];
    b.image=[UIImage imageNamed:@"playbuttone.png"];
    [cell.contentView addSubview:b];
    [b release];
    UIButton *b2=[[UIButton alloc] initWithFrame:CGRectMake(260, 0, 50, 35)];
    [b2 setImage:[UIImage imageNamed:@"buye.png"] forState:UIControlStateNormal];
    [cell.contentView addSubview:b2];
    [b2 release];

    cell.textLabel.textColor=[UIColor colorWithWhite:1 alpha:1];
}

after update:

cell.textLabel.text=[NSString stringWithFormat:@"         %@",[SongsNames objectAtIndex:indexPath.row]];

        [cell.contentView addSubview:b];
       // [b release];
        [cell.contentView addSubview:b2];
        //[b2 release];

        cell.textLabel.textColor=[UIColor colorWithWhite:1 alpha:1];

and in the viewdidload:

- (void)viewDidLoad{

b=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 35, 34)];
b.image=[UIImage imageNamed:@"playbuttone.png"];

b2=[[UIButton alloc] initWithFrame:CGRectMake(260, 0, 50, 35)];
[b2 setImage:[UIImage imageNamed:@"buye.png"] forState:UIControlStateNormal];

}

Answers


You are reloading your images for each call of that function. When scrolling this function gets called really a lot of times which is not neccessary, in particular because your images are static and identical for each cell.

Load the two images once when the view did load, save a reference in the view controller and reuse them. When the table view requests the cell. This very likely will solve your problem.


Need Your Help

How to save webkit page image resources from memory?

python webkit gtk pygtk

I open page with python, gtk, and webkit. Now - how to save image from that page without downloading it again from the internet?

XSLT Create HTML Table for Dynamic XML Columns

xml xslt

I am working on putting a xml data into html table. I am new to xslt and trying to get this done. I have xml with dynamic # of columns in specific format