如何在 UIContainerView 中连接 UICollectionViewController [英] How do I hook up UICollectionViewController in UIContainerView
问题描述
我有一个看起来像这样的应用:
I have an app that looks like this:
ViewController
是我在其中放置 3 个容器视图控制器的父 VC.
我将 UIViewController
子类化为所有三个,Top,Mid &BottomContainerViewControllers.
ViewController
is the parent VC into which I placed 3 container view controllers.
I subclassed UIViewController
for all three, Top, Mid & BottomContainerViewControllers.
这是我的问题.我希望 BottomVC
有一个横向滚动的 UICollectionView
.所以我添加了一个 UICollectionView
如你所见(给它一个漂亮的绿色背景).
Here is my question. I want the BottomVC
to have a UICollectionView
which scrolls sideways. So I added a UICollectionView
as you can see (gave it a nice greenish background).
但我的问题是,我该如何连接?
But my question is, how do I hook this up?
这是我的 BottomContainerViewController.h:
This is my BottomContainerViewController.h:
#import <UIKit/UIKit.h>
@interface BottomContainerViewController : UICollectionViewController <UICollectionViewDataSource, UICollectionViewDelegate>
@property (nonatomic, retain) IBOutlet UICollectionView *collectionView;
@end
而.m文件有以下方法:
And the .m file has the following methods:
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
但是当我运行它时,我得到:
But when I run it I get:
[UICollectionViewController loadView] loaded the "qcP-Hl-Txn-view-aJq-Dc-875" nib but didn't get a UICollectionView.'
UICollectionView
插座已连接.还有什么问题?
The UICollectionView
outlet is connected. What else could be the problem?
推荐答案
创建一个uiviewcontroller类来管理底层容器.像往常一样使用该视图控制器进行链接.连接delegate、datasource、实现delegate、data source……等等……
Create a uiviewcontroller class to manage the bottom container. Link as you normally would using that view controller. Connect delegate, datasource, implement the delegate and data source... etc...
这篇关于如何在 UIContainerView 中连接 UICollectionViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!