У меня есть UITableViewCell
и в этом загружать изображения, поэтому я хочу, чтобы изображения загружали асинхронные сигналы и показывали индикатор активации. Это время загрузки изображений очень велико, и все изображения загружаются после того, как изображения отображаются в виде таблицы. много раз снижается загрузка изображения и пользователь UIInterface висит. и не работаю над любым процессом в приложении. Я очень устал, я использовал библиотеку SDWebImage
. пожалуйста, помогите, как это возможно, спасибоКак использовать SDWebImage
#import "UIImageView+WebCache.h"
@interface pictureViewController()
{
NSArray*picarray;
NSArray*titlearray;
NSArray*idarray;
}
@end
@implementation pictureViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[[[self navigationController] navigationBar] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]}];
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"background2.png"] forBarMetrics:UIBarMetricsDefault];
_tableview.separatorColor = [UIColor yellowColor];
NSURLRequest *req=[[NSURLRequest alloc]initWithURL:[NSURL URLWithString:@"http://edutimeapp.com/toshow/chamber-of-commerc/ws/fetch_gallery.php"]];
response =[[NSMutableData alloc]init];
[NSURLConnection connectionWithRequest:req delegate:self];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[response appendData:data];
NSLog(@"error receving data %@",response);
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSError *error;
//NSLog(@"Error in receiving data %@",error);
NSMutableDictionary *json = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error];
// NSLog(@"response data %@",json);
NSArray *results = [json objectForKey:@"status"];
picarray = [results valueForKey:@"img_url"];
titlearray = [results valueForKey:@"title"];
// NSLog(@"my title is%@",titlearray);
idarray=[results valueForKey:@"id"];
//NSLog(@"my galary id is%@",idarray);
[self.tableview reloadData];
}
// Do any additional setup after loading the view, typically from a nib.
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [picarray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// NSLog(@"tableview cell");
picture_viewcontrollerCell *cell = [tableView dequeueReusableCellWithIdentifier:@"htr"];
if (cell==nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"Cell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
//NSData* imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString: [picarray objectAtIndex:indexPath.row]]];
// UIImage* image = [[UIImage alloc] initWithData:imageData];
//cell.picture.image =image;
cell.titlelbl.text=[NSString stringWithFormat:@"%@",[titlearray objectAtIndex:indexPath.row]];
NSURL*url= [[picarray objectAtIndex:indexPath.row]valueForKey:@"img_url"];
[cell.picture setContentMode:UIViewContentModeScaleAspectFill];
[cell.picture sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"Placeholder.jpg"]];
return cell;
}
@end
'[<__ NSCFString 0x7aff3ea0> valueForUndefinedKey:]: этот класс не является ключевым значением, совместимым с кодировкой для ключа img_url.' –
изменить эту строку NSURL * url = [NSURL URLWithString: [[picarray objectAtIndex: indexPath.row] valueForKey: @ "img_url"]]; с вашей предыдущей строкой и проверить, существует ли эта ошибка или нет .. проверьте обновленную строку в моем коде .. –
'[<__ NSCFString 0x79f168a0> valueForUndefinedKey:]: этот класс не является ключевым значением, совместимым с кодировкой для ключа img_url.' та же ошибка показать ниже –