I have problem I am loading UITableViewCell
with images
all images shown to me but the problem is UTableView
scroll
very slow this is the code
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
customSearchesCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DefaultCell"];
if(cell == nil)
{
cell =[[customSearchesCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"DefaultCell"];
}
searchobjectval =[self.arrSearchResult objectAtIndex:indexPath.row];
cell.location.text =searchobjectval.location;
cell.title.text = searchobjectval.title;
cell.cost.text = searchobjectval.roomCost;
cell.desc.text =searchobjectval.description;
[tableView setSeparatorColor:[UIColor blueColor]];
UIView *myView = [[UIView alloc] init];
if (indexPath.row % 2)
{
UIColor* clr = [UIColor colorWithRed:0.4f green:0.6f blue:0.8f alpha:1];
myView.backgroundColor = clr;
}
else
{
myView.backgroundColor = [UIColor whiteColor];
}
cell.backgroundView = myView;
NSLog(@" search object image %@",searchobjectval.imgLink);
UIImage *ret = [self imageNamed:[NSString stringWithFormat: @"http://192.95.76.78/bedspace/new_arrivals_img/%@",searchobjectval.idVal ] cache:YES andsearchObj:searchobjectval];
cell.imgVw.image = ret;
return cell;
}
// images caching in dictionary
- (UIImage*)imageNamed:(NSString*)imageNamed cache:(BOOL)cache andsearchObj:(clsSearch *)searchObj
{
UIImage* retImage = [staticImageDictionary objectForKey:imageNamed];
@try
{
if (retImage == nil)
{
retImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imageNamed]]];
if (cache)
{
if (staticImageDictionary == nil)
staticImageDictionary = [NSMutableDictionary new];
[staticImageDictionary setObject:retImage forKey:imageNamed];
}
}
}
@catch (NSException *exception)
{
NSLog(@"exception %@",exception);
}
@finally {
NSLog(@"finally block execute here");
}
return retImage;
}
Kindly tell me how I can fix this problem, I had paste the code inside if (cell == nil)
but not successfull yet.