【发布时间】:2013-06-23 16:30:38
【问题描述】:
基本上我已经写了大约 3 天的 iOS 应用程序(在阅读了一本书以了解设计模式和框架等的基本知识之后),并且已经花了一整天的时间。我无法显示我的CollectionView。我有一个以TabBarView 开头的故事板,两个选项卡(一个是TableView,另一个只是UIView)工作,但第三个选项卡(UICollectionView)只显示黑屏即使在设置之后。
我是如何设置的:
1) 将 ViewController 拖到情节提要
2) 在我的UITabBarController 和新的ViewController 之间建立了关系segue
3) 将UICollectionView 拖到新的ViewController
4) 将4个UICollectionViewCell's拖到CollectionView
5) 将 4 个UILabels 拖入上述CollectionViewCell's
6) 在新的CollectionView's 委托和数据源与我的CollectionView 类的头文件之间建立了连接(这可能是我出错的地方,我没有将我的ViewController.h 类连接为我将这个用于我的UITableView,并认为有必要开设一个新课程)
7) 在我的CollectionView.m 文件中声明了以下方法
- (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 更多的是一种导航技术,而不是显示精彩的图像或任何东西,稍后当它们实际显示在模拟器中时,我将使用通用图像填充它们。 谢谢
【问题讨论】:
标签: iphone objective-c xcode ipad collectionview