ios - 无法在 Collection View 中加载数据?

标签 ios objective-c json http

我从一个 URL 获取数据并对我的密码进行编码并执行 shaa256 然后我再次传递密码以从我的 url 获取数据

网址:http://exampleurl/users

而且我可以在我的控制台中打印我的 Json 响应。它工作正常。现在我想在我的 Collection View 中显示我的数据(如网格形式)。我做了所有的 Storyboard工作,我做了所有的委托(delegate)方法.

我的问题:

  1. 获取错误 'UICollectionView dataSource is not set'
  2. 我的数据没有加载到 Collection View 中。

帮我提前谢谢!

最佳答案

为您的刷新数据

for(int i=0;i<[arrayFiles count];i++)
{
    NSString *strCreatedTime = [NSString stringWithFormat:@"%@",[[arrayFiles objectAtIndex:i] valueForKey:@"created_time"]];
    NSString *strLastModifiedTime = [NSString stringWithFormat:@"%@",[[arrayFiles objectAtIndex:i] valueForKey:@"last_modified_time"]];
    NSString *strID = [NSString stringWithFormat:@"%@",[[arrayFiles objectAtIndex:i] valueForKey:@"id"]];
    NSString *strName = [NSString stringWithFormat:@"%@",[[arrayFiles objectAtIndex:i] valueForKey:@"name"]];


    [arrayPDFName addObject:strName];
}

之后调用这一行重新加载/刷新/更新数据

 dispatch_async(dispatch_get_main_queue(), ^ {
[self.mycollectionView reloadData];
});

对于你的第一个错误

- (void)viewDidLoad {
[super viewDidLoad];


self.mycollectionView.dataSource = self;
self.mycollectionView.delegate = self;

 [self getdata];

}

检查您的 .h 文件,确保声明您的对象符合数据源和委托(delegate)协议(protocol)。例如

@interface ViewController : UIViewController <UICollectionViewDelegate, UICollectionViewDataSource>

关于ios - 无法在 Collection View 中加载数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33482178/

相关文章:

iphone - NSString 未正确显示

objective-c - 检测长按 UINavigationItem 的后退按钮

ios - 当 iPhone 在 objective-c 中打开或关闭静音时获取通知

php - 获取值作为数组值

java - 以 JSON 格式刷新自定义对象的 HashMap

javascript - 在没有 node.js 的情况下写入 .json 文件

ios - Xamarin.iOS 错误 : The Apple iOS SDK is not installed.(iOS9、XCode 7 测试版)

ios - 具有交错开始时间的 CAKeyframeAnimation

ios - swifty json解析数组对象

ios - 无法在 Xcode 11.4 中导出测试结果