gpt4 book ai didi

ios - 将 CollectionViewController 作为 ChildViewController 添加到 UIView

转载 作者:搜寻专家 更新时间:2023-10-30 20:19:50 25 4
gpt4 key购买 nike

我正在尝试创建一个 View ,其中包含三个具有不同 View Controller 的 subview (UICollectionViewControllerpageviewcontrolleruiviewcontroller)。我可以添加一个 uiviewcontroller 但不允许添加其他两个 Controller 。我收到此错误.....

Incompatible pointer types sending 'UICollectionView *__weak' to parameter of type 'UIViewController *'

他们有什么方法可以将这些 Controller 添加到我的 subview 中吗?

最佳答案

我不知道你为什么要在 View 中添加 ViewControllers,我从来不需要它。我试着这样做,如果可以帮助你这是我的运行代码:

ViewController.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

@property (nonatomic, retain) UICollectionViewController *collectionViewController;
@property (nonatomic, retain) UIPageViewController *pageViewController;
@property (nonatomic, retain) UIViewController *simpleViewController;

@end

ViewController.m

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

@synthesize collectionViewController;
@synthesize pageViewController;
@synthesize simpleViewController;


- (void)viewDidLoad
{
[super viewDidLoad];

UICollectionViewLayout *layout = [[UICollectionViewLayout alloc] init];
collectionViewController = [[UICollectionViewController alloc] initWithCollectionViewLayout:layout];
pageViewController = [[UIPageViewController alloc] init];
simpleViewController = [[UIViewController alloc] init];

// Do your stuff with this controllers

[self.view addSubview:collectionViewController.view];
[self.view addSubview:pageViewController.view];
[self.view addSubview:simpleViewController.view];

}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end

关于ios - 将 CollectionViewController 作为 ChildViewController 添加到 UIView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14895130/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com