Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UICollection视图未加载_Ios_Objective C_Api_Uicollectionview - Fatal编程技术网

Ios UICollection视图未加载

Ios UICollection视图未加载,ios,objective-c,api,uicollectionview,Ios,Objective C,Api,Uicollectionview,我已经从Steam中实现了两个api,用于从玩家背包中获取物品,并将其与GetSchema api相匹配,以获取图像url和每个物品的描述。我首先在表格视图和单元格中显示信息,它工作得非常好。现在,我决定使用UICollectionView显示信息,问题是代码编译得很好,但是API没有被调用,也没有显示任何内容。这是我的MasterViewController.h和.m文件,它是UICollectionView的自定义类 MasterViewController.h #导入 @界面主视图控制器:

我已经从Steam中实现了两个api,用于从玩家背包中获取物品,并将其与GetSchema api相匹配,以获取图像url和每个物品的描述。我首先在表格视图和单元格中显示信息,它工作得非常好。现在,我决定使用UICollectionView显示信息,问题是代码编译得很好,但是API没有被调用,也没有显示任何内容。这是我的MasterViewController.h和.m文件,它是UICollectionView的自定义类

MasterViewController.h

#导入
@界面主视图控制器:UICollectionViewController
@结束

MasterViewController.m

#import "MasterViewController.h"
#import "Group.h"
#import "Item.h"
#import "SteamManager.h"
#import "SteamCommunicator.h"
#import "backpackIcons.h"


@interface MasterViewController () <SteamManagerDelegate> {
 NSArray *_groups;
NSArray *_itemGroups;
NSArray *_backpackItems;
NSArray *_backpackItemPhotos;
SteamManager *_manager;
}
@end

@implementation MasterViewController

- (void)viewDidLoad
{
[super viewDidLoad];
_manager = [[SteamManager alloc] init];
_manager.communicator = [[SteamCommunicator alloc] init];
_manager.communicator.delegate = _manager;
_manager.delegate = self;
NSLog(@"Starting");
[self startFetchingGroups];
}
#pragma mark - Creating Backpack Icons
-(NSArray *)createBackpackIcons:(NSArray *)groups usingItemGroups:(NSArray *)items
{
    NSMutableArray *backpackItems = [[NSMutableArray alloc] init];
    for (NSInteger i = 0; i < _groups.count; i++) {
    Group *group = _groups[i];
    NSString *defindex1 = [NSString stringWithFormat:@"%@", group.defindex];
    for (NSInteger j = 0; j < _itemGroups.count; j++)
    {
        Item *item = _itemGroups[j];
        NSString *defindex2 = [NSString stringWithFormat:@"%@", item.defindex];
        if([defindex1 isEqualToString:defindex2])
        {
            NSLog(@"%@", item.name);
            backpackIcons *backpack = [[backpackIcons alloc] init];
            backpack.name = item.name;
            backpack.original_id = group.original_id;
            backpack.defindex = item.defindex;
            backpack.level = group.level;
            backpack.quality = group.quality;
            backpack.image_url = item.image_url;
            backpack.item_description = item.item_description;
            [backpackItems addObject:backpack];
        }
    }
}
return backpackItems;
}
#pragma mark - Notification Observer
- (void)startFetchingGroups
{
    [_manager fetchGroups];
}

#pragma mark - SteamManagerDelegate
- (void)didReceiveGroups:(NSArray *)groups
{
    _groups = groups;
}

- (void)didReceieveItemGroups:(NSArray *)groups
{
    _itemGroups = groups;
    _backpackItems = [self createBackpackIcons:_groups
                           usingItemGroups:_itemGroups];
dispatch_async(dispatch_get_main_queue(), ^{
    [self.collectionView reloadData];
});
}
- (void)fetchingGroupsFailedWithError:(NSError *)error
{
NSLog(@"Error %@; %@", error, [error localizedDescription]);
}

#pragma mark - Collection View
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:   (NSInteger)section {
    return _groups.count;
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = @"Cell";
backpackIcons *item = _backpackItems[indexPath.row];
NSString *photoURL = item.image_url;
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
UIImageView *itemImageView = (UIImageView *)[cell viewWithTag:100];
itemImageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:photoURL]]];

return cell;
}
/*
#pragma mark - Table View

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return _groups.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
DetailCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];

Group *group = _groups[indexPath.row];
Item *group2 = _itemGroups[indexPath.row];
backpackIcons *group3 = _backpackItems[indexPath.row];
[cell.nameLabel setText:[NSString stringWithFormat:@"%@", group3.level]];
[cell.originalidLabel setText:[NSString stringWithFormat:@"%@", group3.original_id]];
[cell.qualityLabel setText:[NSString stringWithFormat:@"%@", group3.image_url]];
[cell.levelLabel setText:[NSString stringWithFormat:@"%@", group3.item_description]];

return cell;
}
*/
@end
#导入“MasterViewController.h”
#导入“Group.h”
#导入“Item.h”
#导入“SteamManager.h”
#导入“SteamCommunicator.h”
#导入“backpackings.h”
@接口MasterViewController(){
NSArray*_组;
NSArray*_项目组;
NSArray*_背包物品;
NSArray*(照片);
蒸汽经理*\u经理;
}
@结束
@主视图控制器的实现
-(无效)viewDidLoad
{
[超级视图下载];
_manager=[[streammanager alloc]init];
_manager.communicator=[[streamcommunicator alloc]init];
_manager.communicator.delegate=\u manager;
_manager.delegate=self;
NSLog(“启动”);
[自启动蚀刻组];
}
#pragma标记-创建背包图标
-(NSArray*)创建背包图标:(NSArray*)组使用项目组:(NSArray*)项
{
NSMUTABLEARRY*BACKBACKItems=[[NSMUTABLEARRY alloc]init];
对于(NSInteger i=0;i<\u groups.count;i++){
组*组=_组[i];
NSString*defindex1=[NSString stringWithFormat:@“%@”,group.defindex];
对于(NSInteger j=0;j<\u itemGroups.count;j++)
{
项目*项目=_项目组[j];
NSString*defindex2=[NSString stringWithFormat:@“%@”,item.defindex];
if([Definedx1 isEqualToString:Definedx2])
{
NSLog(@“%@”,项名称);
背包图标*BACKBACK=[[BACKBACKICONS ALOC]init];
backpack.name=item.name;
backpack.original_id=group.original_id;
backpack.defindex=item.defindex;
backpack.level=group.level;
背包质量=组质量;
backpack.image\u url=item.image\u url;
backpack.item_description=item.item_description;
[背包物品添加对象:背包];
}
}
}
归还物品;
}
#pragma标记-通知观察员
-(无效)开始蚀刻组
{
[_管理器组];
}
#pragma标记-蒸汽管理器
-(void)didReceiveGroups:(NSArray*)组
{
_组=组;
}
-(void)didReceiveItemGroups:(NSArray*)组
{
_项目组=组;
_BACKBACKItems=[self-CreateBackBACKBACKICONS:\u组
usingItemGroups:_itemGroups];
dispatch\u async(dispatch\u get\u main\u queue()^{
[self.collectionView-reloadData];
});
}
-(void)fetchingGroupsFailedWithError:(n错误*)错误
{
NSLog(@“Error%@;%@”,Error,[Error localizedDescription]);
}
#pragma标记-集合视图
-(NSInteger)collectionView:(UICollectionView*)collectionView项目编号截面:(NSInteger)截面{
返回_groups.count;
}
-(UICollectionViewCell*)collectionView:(UICollectionView*)collectionView cellForItemAtIndexPath:(NSIndexPath*)indexPath{
静态NSString*标识符=@“单元格”;
backpackIcons*item=_backpackItems[indexPath.row];
NSString*photoURL=item.image\u url;
UICollectionViewCell*cell=[collectionView dequeueReusableCellWithReuseIdentifier:indexPath的标识符:indexPath];
UIImageView*itemImageView=(UIImageView*)[带标记的单元格视图:100];
itemImageView.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:photoURL]];
返回单元;
}
/*
#pragma标记-表视图
-(NSInteger)表视图:(UITableView*)表视图行数节:(NSInteger)节
{
返回_groups.count;
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
DetailCell*cell=[tableView dequeueReusableCellWithIdentifier:@“cell”forIndexPath:indexPath];
Group*Group=_groups[indexPath.row];
Item*group2=_itemGroups[indexath.row];
backpackIcons*group3=_backpackItems[indexPath.row];
[cell.nameLabel setText:[NSString stringWithFormat:@“%@”,group3.level];
[cell.originalidLabel setText:[NSString stringWithFormat:@“%@”,group3.original_id];
[cell.qualityLabel setText:[NSString stringWithFormat:@“%@”,group3.image_url];
[cell.levelLabel setText:[NSString stringWithFormat:@“%@”,group3.item_description];
返回单元;
}
*/
@结束
更新:您可以在这里的dropbox上查看整个项目:
更新#2:Collection视图现在不知怎么起作用了,我不知道我做了什么。感谢所有帮助过我的人。

我看不到collectionView数据源或委托被设置在任何地方

self.collectionView.dataSource = self;
self.collectionView.delegate = self;
如下所示:

- (void)didReceiveGroups:(NSArray *)groups
{
    _groups = groups;
   [_collectionView reloadData]; //using your instance here.
}
似乎在设置数据源之前就得到了对象。您可以尝试重新加载collectionView或重新生成代码,在调用collectionView数据源方法之前,您在其中获得了所有组


确保在上述方法中为_组设置了值。如果你在这里调试它,应该是400个对象

您确定_groups.count>0吗?你能在numberOfRowsInSection方法中调试它吗?是的,我调试了它,并且_groups.count大于0,它的值为400。问题是两个API都没有被调用,因为我调试了它,并且NSLog消息没有显示。我把整个项目上传到上面链接中的dropbox上。请你看一下,告诉我问题出在哪里好吗;请参阅链接