NevzatR
NevzatR

Reputation: 245

Table View Scrolling cause problems when I use dynamic data

When I use static data there is no problem but I use dynamic data with Web services there is problem (table view scrolling cause crash program) why? If I comment these lines add static data it works;

//tempCs is NSDictionary
tempDc = [arrHaberler objectAtIndex:indexPath.row];
cell.textLabel.text = [tempDc valueForKey:@"short_header"];

NSData *imgData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:[tempDc valueForKey:@"iphone_src"]]];
UIImage *myImage = [[[UIImage alloc] initWithData:imgData] autorelease];
cell.imageView.image = myImage;

Upvotes: 1

Views: 376

Answers (4)

jv42
jv42

Reputation: 8593

You don't release the imgData. You'd want to do that after creating the UIImage.

Other than that, from your description, maybe the numbersOfRowsInSection method has an error?


EDIT (after discussion):

(crash due to unrecognized selector (ie method from NSArray) sent to instance of NSString)

There are many ways you can come to this state, including accessing some memory that was released and reused (ie missing a retain), or overwriting an array with a string due to some parsing yielding a wrong result.

Upvotes: 1

NevzatR
NevzatR

Reputation: 245

I try something with made an comment another lines and problem is on this line:

tempDc = [arrHaberler objectAtIndex:indexPath.row];

I change "indexPath.row" to "0" still cause crash... Problem about when is assign data to NSDictionary

Upvotes: 1

Sudhanshu
Sudhanshu

Reputation: 3960

@VNevzatR i am just asking you that Are you are calling plenty no of images from somewhere....because this is no the problem you UITableView as you said working fine in static data,the problem is some where else, so if you are calling plenty of images at a time....Try doing this way...release that pool.

-(void) parseImages
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    //Fetch your images here

    [self performSelectorOnMainThread:@selector(Done) withObject:nil waitUntilDone:YES];
    [pool release];
}

-(void) Done {
    [self.tableView reloadData];
}

Hope it will resolve your problem...Good Luck

Upvotes: 0

knuku
knuku

Reputation: 6102

There is no null-checking (setting NSData *imgData and setting UIImage *myImage) and there in a synchronous call to server. fmpov, problem is out there.

Upvotes: 0

Related Questions