我想从屏幕截图加载图片,如屏幕截图所示。
我正在使用此代码将标题图片加载到我的imageview中。
PFQuery *query = [PFQuery queryWithClassName:@"AppOfTheDay"];
[query getObjectInBackgroundWithId:@"WDJpxs4PzH"
block:^(PFObject *retreive, NSError *error) {
{
NSString *text = [retreive objectForKey:@"description"];
if (error) {
[MBProgressHUD hideHUDForView:self.view animated:YES];
UIAlertView *error=[[UIAlertView alloc]initWithTitle:@"Error" message:@"Connection Failed" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[error show];
}
else{
PFFile *imageFile = [retreive objectForKey:@"header"];
[imageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
if (error) {
[MBProgressHUD hideHUDForView:self.view animated:YES];
UIAlertView *error=[[UIAlertView alloc]initWithTitle:@"Error" message:@"Something went wrong" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[error show];
}
else{
UIImage *image = [UIImage imageWithData:data];
_headerImage.image=image;
_appDescription.text=text;
[MBProgressHUD hideHUDForView:self.view animated:YES];
}
}];
}
}
}];
我的问题是如何将我的其他三张图片同样加载到图片视图中?
答案 0 :(得分:0)
实现延迟加载图片。 例如-NSURL * url = [NSURL URLWithString:urlString];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
if ( queue == nil )
{
queue = [[NSOperationQueue alloc] init];
}
[NSURLConnection sendAsynchronousRequest:urlRequest queue:queue completionHandler:^(NSURLResponse * resp, NSData *data, NSError *error)
{
dispatch_async(dispatch_get_main_queue(),^
{
if ( error == nil && data )
{
UIImage *urlImage = [[UIImage alloc] initWithData:data];
thumbnail.image = urlImage;
}
});
}];
答案 1 :(得分:0)
我希望它会帮助你很多,它会以最佳加载速度排序你的问题
// yourclass.h
AsyncImageView *imageasy,*imageasy1, *imageasy2,imageasy3;
yourclass.m
PFQuery *query = [PFQuery queryWithClassName:@"AppOfTheDay"];
[query getObjectInBackgroundWithId:@"WDJpxs4PzH"
block:^(PFObject *comment, NSError *error) {
if (!error) {
PFFile *post = [comment objectForKey:@"PhotoName"];
PFFile *post2 = [comment objectForKey:@"logo"];
PFFile *post3 = [comment objectForKey:@"similar1"];
PFFile *post4 = [comment objectForKey:@"similar2"];
imageasy=[[AsyncImageView alloc] init];
imageasy1=[[AsyncImageView alloc] init];
imageasy2=[[AsyncImageView alloc] init];
imageasy3=[[AsyncImageView alloc] init];
[imageasy setImageURL:[NSURL URLWithString:[post url]]];
[imageasy1 setImageURL:[NSURL URLWithString:[post2 url]]];
[imageasy2 setImageURL:[NSURL URLWithString:[post3 url]]];
[imageasy3 setImageURL:[NSURL URLWithString:[post4 url]]];
}];