gpt4 book ai didi

iOS 应用程序 - 在 GridView 中显示来自 JSON URL 列表的图像。

转载 作者:行者123 更新时间:2023-11-28 20:18:32 25 4
gpt4 key购买 nike

我将 URL 列表存储在 MYSQL 数据库表中,并且我已经能够通过 JSON 成功检索 URL。

但是,既然我有了 JSON,我不确定如何在我的 iPhone 应用程序的图库类型 View 中显示图像。

我计划拥有一个巨大的 URL 列表,用于在数据库中显示图像,我想一次显示 x 个数量,然后一旦用户滚动到末尾,我想再显示 x 个数量。像品脱店一样。

有什么提示吗?

#import "mySQLAppViewController.h"


@interface mySQLAppViewController (){

}

- (IBAction)loadJSON:(id)sender;

@end


@implementation mySQLAppViewController

- (IBAction)loadJSON:(id)sender {

NSString *dataUrl = [NSString stringWithFormat:@"http://MYDOMAIN.com/results.php"];
NSURL *url = [NSURL URLWithString:dataUrl];
NSURLRequest *request = [NSURLRequest requestWithURL:url];

AFJSONRequestOperation *operation =
[AFJSONRequestOperation JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {

for (int i =0 ; i < [JSON count]; i++) {

//NSString *image_url = JSON[i][@"image_url"];
//NSLog(@"%@", image_url);
//^^THIS SUCESSFULLY LOGS THE URL LINKS (I.E. HTTP://MYDOMAIN.COM/CAR.JPG)

NSURL *imageURL = [NSURL URLWithString:JSON[i][@"image_url"]];
NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
UIImage *image = [UIImage imageWithData:imageData];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];


}

}

failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"Error Retrieving Weather"
message:[NSString stringWithFormat:@"%@",error]
delegate:nil
cancelButtonTitle:@"OK" otherButtonTitles:nil];
[av show];
}];

[operation start];

}

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end

最佳答案

听起来你想看看 UICollectionView。这是一个帮助您入门的教程: Beginning UICollectionView In iOS 6 .

关于iOS 应用程序 - 在 GridView 中显示来自 JSON URL 列表的图像。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16908101/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com