简体   繁体   English

我可以在一个应用程序中集成UIViewController和UICollectionViewController吗?

[英]Can I integrate UIViewController and UICollectionViewController in one app?

In an app I'm making, I'm trying to mix a UIViewContoller and a UICollectionViewController in two different view controllers. 在我制作的应用程序中,我试图在两个不同的视图控制器中混合使用UIViewContoller和UICollectionViewController。 The CollectionViewController Cells won't show up in the app. CollectionViewController单元将不会显示在应用程序中。 I was wondering how I incorporate it in to my interface in the viewcontroller.h. 我想知道如何将其合并到viewcontroller.h的界面中。

Current ViewController.h 当前ViewController.h

#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>

@interface ViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate>
- (IBAction)cameraButtonClicked:(id)sender;
@property (strong, nonatomic) IBOutlet UIImageView *imageView;


@end
@interface ViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate, UICollectionViewDelegate, UICollectionViewDataSource>
- (IBAction)cameraButtonClicked:(id)sender;
@property (strong, nonatomic) IBOutlet UIImageView *imageView;
@property (strong, nonatomic) UICollectionView *collectionView
@end

Then, on your ViewController.m : 然后,在您的ViewController.m

- (void)viewDidload{
    self.collectionView = ({
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
        flowLayout.itemSize = CGSizeMake(300, 107);
        flowLayout.minimumLineSpacing = 10.f;
        [[UICollectionView alloc]initWithFrame:self.view.frame collectionViewLayout:flowLayout];
    });

    [self.collectionView setAlwaysBounceVertical:YES];
    [self.collectionView setContentInset:UIEdgeInsetsMake(60, 0, 0, 0)];
    self.collectionView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.collectionView];

    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
    [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"Cell"];
}

Also, I think you're kind of confused on the term "View Controller" and "View." 另外,我认为您对术语“视图控制器”和“视图”感到困惑。 A UICollectionViewController is the object you drag onto your Storyboard from the Objects Library (on your Utilities panel). UICollectionViewController是您从“对象库”(在“实用程序”面板上)拖到故事板上的对象。 A UICollectionView is a subclass of UIScrollView (just like UITableView ) that incorporates a series of methods that give it it's behavior. UICollectionViewUIScrollView的子类(就像UITableView一样),它合并了一系列赋予其行为的方法。

Please note that, since you're conforming to the UICollectionViewDataSource and the UICollectionViewDelegate protocols, you should implement the @required methods from those protocols: 请注意,由于您符合UICollectionViewDataSourceUICollectionViewDelegate协议,因此@required这些协议中实现@required方法:

  1. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView;
  2. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section;
  3. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath;

Hope I helped. 希望我能帮上忙。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何实现从UICollectionViewController到UIViewController的自定义UIViewController转换? - How can I achieve this custom UIViewController Transition from UICollectionViewController to UIViewController? 如何创建一个转接表单 UIViewController 到 UICollectionViewController? - 以编程方式 - How can I create a segue form UIViewController to UICollectionViewController ? - Programmatically 我们如何决定使用 UICollectionViewController 还是 UIViewController? - How can we decide to use UICollectionViewController or UIViewController? 嵌套在普通UIViewController中的UICollectionViewController - UICollectionViewController nested in a normal UIViewController 将UICollectionViewController添加到UIViewController不起作用 - Adding UICollectionViewController to UIViewController Not Working UIViewController 内的 UICollectionViewController 或 CollectionView - UICollectionViewController or CollectionView inside UIViewController 如何将UISearchDisplayController与UICollectionViewController一起使用? - How can I use UISearchDisplayController with UICollectionViewController? 如何在 UICollectionViewController 的标头中访问 UISegmentedControl? - How can I access UISegmentedControl in header of UICollectionViewController? 从UICollectionViewController导航到UIViewController时,UIViewController闪烁 - Blinking of UIViewController while navigation from UICollectionViewController to UIViewController 如何在UICollectionviewcontroller中显示文本字段? - How can I show the textfield in the UICollectionviewcontroller?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM