0
嗨,大家好,因为我有一个UITableView与自定义单元格,我解析一些XML数据,使单元格时尚我使用此代码为渐变背景,现在的问题是,我的应用程序滞后一次我在tableview中向下或向上滚动。 这是我的代码:uiscrollview滞后梯度单元格背景
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:
(NSIndexPath *)indexPath{
static NSString *CellIdentifier [email protected]"ProvidersCell";
ProvidersViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[ProvidersViewCell alloc]initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
}
NSString*imageurl = [XMLReader getValue:[[providers objectAtIndex:indexPath.row] objectForKey: @"Image"]];
if ([imageurl isEqual: @""]) {
UIImage* myImage = [UIImage imageWithData:
[NSData dataWithContentsOfURL:
[NSURL URLWithString:@"http://www./nopic.jpg"]]];
cell.provider_img.image=myImage;
}else{
UIImage* myImage = [UIImage imageWithData:
[NSData dataWithContentsOfURL:
[NSURL URLWithString:imageurl]]];
cell.provider_img.image=myImage;
}
[cell setBackgroundColor:[UIColor clearColor]];
CAGradientLayer *grad = [CAGradientLayer layer];
grad.frame = cell.bounds;
grad.colors = [NSArray arrayWithObjects:(id)[[UIColor colorWithRed:241/255.0 green:241/255.0 blue:242/255.0 alpha:1.0] CGColor],(id)[[UIColor colorWithRed:231/255.0 green:231/255.0 blue:232/255.0 alpha:1.0] CGColor], (id)[[UIColor colorWithRed:207/255.0 green:207/255.0 blue:207/255.0 alpha:1.0] CGColor], nil];
[cell setBackgroundView:[[UIView alloc] init]];
[cell.backgroundView.layer insertSublayer:grad atIndex:0];
CAGradientLayer *selectedGrad = [CAGradientLayer layer];
selectedGrad.frame = cell.bounds;
selectedGrad.colors = [NSArray arrayWithObjects:(id)[[UIColor colorWithRed:24/255.0 green:215/255.0 blue:229/255.0 alpha:1.0] CGColor],(id)[[UIColor colorWithRed:22/255.0 green:206/255.0 blue:219/255.0 alpha:1.0] CGColor], (id)[[UIColor colorWithRed:9/255.0 green:173/255.0 blue:185/255.0 alpha:1.0] CGColor], nil];
[cell setSelectedBackgroundView:[[UIView alloc] init]];
[cell.selectedBackgroundView.layer insertSublayer:selectedGrad atIndex:0];
cell.provider_name.text =[XMLReader getValue:[[providers objectAtIndex:indexPath.row] objectForKey: @"Name"]];
cell.provider_condition.text = [XMLReader getValue:[[providers objectAtIndex:indexPath.row] objectForKey: @"Condition"]];
cell.provider_payout.text = [XMLReader getValue:[[providers objectAtIndex:indexPath.row] objectForKey: @"Payout"]];
NSString*rating = [XMLReader getValue:[[providers objectAtIndex:indexPath.row]objectForKey:@"Rating"]];
NSInteger rate = [rating integerValue];
return cell;}
哦,我明白了,我会试试这个谢谢。 – Musashi
可能这2个问题会严重影响iphone电池吗? – Musashi
我不这么认为 – Claudio