我有一個UIViewController
其上有一個UICollectionView
,但Xcode看起來不像我在互聯網或YouTube上找到的每個教程 - 當我拖動一個UICollectionViewCell
以放置在UICollectionView
,它不會讓我放置它。如何將UICollectionViewCell鏈接到UICollectionView
現在我很困惑我如何將我的細胞連接到UICollectionView
。 這是viewController.h文件:
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return [self.imagesArray count];
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
ImageViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"imageCell" forIndexPath:indexPath];
NSString *myImageString = [self.imagesArray objectAtIndex:indexPath.row];
cell.imageView.image = [UIImage imageNamed:myImageString];
return cell;
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
return CGSizeMake(100.0, 100.0);
}
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
return UIEdgeInsetsMake(5, 5, 5, 5);
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.collectionView.delegate = self;
self.collectionView.dataSource = self;
//[self.collectionView registerClass:[ImageViewCell class] forCellWithReuseIdentifier:@"imageCell"];
self.imagesArray = @[@"shirt1.PNG", @"pants.png", @"pants2.png"];
}
我沒有用故事板界面,但個別廈門國際銀行的
。當我運行這一切時出現的是空白的黑屏。我錯過了什麼?