我有问题我正在加载显示给我UITableViewCell
的images
所有图像但问题UTableView
scroll
很慢这是代码
- (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;
}
请告诉我如何解决此问题,我已将代码粘贴到其中if (cell == nil)
但尚未成功。