用于iPad应用程序的iOS自定义网格视图,用于显示下载的图像

用于iPad应用程序的iOS自定义网格视图,用于显示下载的图像,ios,iphone,objective-c,ipad,uicollectionview,Ios,Iphone,Objective C,Ipad,Uicollectionview,添加集合视图类型的对象,然后通过集合检查器建立正确的连接 在.h文件中 IBOutlet UICollectionView *myCollection; 在viewdidload中 myCollection.delegate = self; myCollection.dataSource = self; 数据源/委托方法包括: - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSe

添加集合视图类型的对象,然后通过集合检查器建立正确的连接

在.h文件中

IBOutlet UICollectionView   *myCollection;
在viewdidload中

 myCollection.delegate = self;
myCollection.dataSource = self;
数据源/委托方法包括:

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:   (NSInteger)section
{
return 15;
}

 // The cell that is returned must be retrieved from a call to -  dequeueReusableCellWithReuseIdentifier:forIndexPath:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView  cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell * cell = [collectionView  dequeueReusableCellWithReuseIdentifier:@"CellID" forIndexPath:indexPath];

cell.backgroundColor=[UIColor greenColor];

return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout: (UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *  )indexPath
{
return CGSizeMake(100, 100);
}

-(void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:  (NSIndexPath *)indexPath
{

}
获取此错误

could not dequeue a view of kind: UICollectionElementKindCell with identifier CellID -   must register a nib or a class for the identifier or connect a prototype cell in a   storyboard'

我现在该怎么办…请帮我解决

您可以使用
UICollectionView
在iOS中显示网格视图

例如:

在HAViewController.h中

#import <UIKit/UIKit.h>

@interface HACollectionCell : UICollectionViewCell

@end

@interface HAViewController : UIViewController <UICollectionViewDataSource, UICollectionViewDelegate>

@end

谢谢

您是否尝试了任何操作但遇到了问题?您是否将[collectionView注册表类:[HACollectionCell类]forCellWithReuseIdentifier:@“CellID”]@纳塔拉扬:谢谢你带我……但请告诉我你在哪里安家it@Natarajan是的,我做到了…谢谢…只需在viewdidload[myCollection registerClass:[DetailInvoicing2 class]forCellWithReuseIdentifier:@“CellID”];@接口HACollectionCell:UICollectionViewCell@end…。你能告诉我这是什么意思吗。如何以及为什么包含itIt将用于将自定义收集单元注册到UICollectionView。Ex:[collectionView注册表类:[HACollectionCell类]forCellWithReuseIdentifier:@“CellID]”;您可以在HACollectionCell中进行更多自定义。它将与UITableView自定义单元格相同。请检查我编辑的问题…我已尝试,但出现一些异常…:(
#import "HAViewController.h"    

@implementation HACollectionCell


@end

@implementation HAViewController

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

    UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc] init];

    UICollectionView * collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.frame.size.width, self.view.frame.size.width) collectionViewLayout:layout];

    collectionView.delegate = self;

    collectionView.dataSource = self;

    [collectionView registerClass:[HACollectionCell class] forCellWithReuseIdentifier:@"CellID"];

    [self.view addSubview:collectionView];

    collectionView = nil;
}

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

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 15;
}

// The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CellID" forIndexPath:indexPath];

    cell.backgroundColor=[UIColor greenColor];

    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(100, 100);
}

-(void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath
{

}

@end