基本上我已经写了大约 3 天的 iOS 应用程序(在阅读了一本书以了解设计模式和框架等的基本知识之后),并且花了一整天的时间。我无法CollectionView显示。我有一个以 a 开头的情节提要,TabBarView两个选项卡(一个是 a TableView,另一个只是 a UIView)工作,但第三个选项卡(UICollectionView)即使在设置后也只是显示黑屏。我是如何设置的:
1) 将 ViewController 拖到情节提要
2)segue在我UITabBarController和新之间建立了关系ViewController
3)拖到UICollectionView新的ViewController
4) 将 4UICollectionViewCell's拖到CollectionView
5)将4UILabels拖入说CollectionViewCell's
6)在新的CollectionView's委托和数据源与我的CollectionView班级的头文件之间建立了连接(这可能是我出错的地方,我没有与我的ViewController.h班级建立联系,因为我为我的班级使用了这个UITableView并认为一个新班级是必要的)
CollectionView.m7)在我的文件中声明了以下方法
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
//Populates each cell using the data given (no data in this case).
//Should return a CollectionViewCell.
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
return cell;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
//Gets the number of cells in each section.
//Should return an integer value.
return 2;
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
//Tells the collection view the number of sections it should have.
//Should return an integer value.
return 4;
}
我觉得我错过了一些东西,因为这个逻辑对我作为一名程序员来说是有意义的,但是,在 Xcode 方面的经验如此之少,也许我忘了把这个类与我的CollectionView或其他东西联系起来。有人知道我哪里出错了吗?
顺便说一句,如果您想知道,我使用此 CollectionView 更多的是一种导航技术,而不是显示精彩的图像或任何东西,稍后当它们实际出现在模拟器中时,我将使用通用图像填充它们。谢谢