Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/100.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios ContainerViewController委托给ChildViewController_Ios_Objective C_Uiviewcontroller_Delegates - Fatal编程技术网

Ios ContainerViewController委托给ChildViewController

Ios ContainerViewController委托给ChildViewController,ios,objective-c,uiviewcontroller,delegates,Ios,Objective C,Uiviewcontroller,Delegates,ContainerViewController将方法-delegateMethod委托给ChildViewController 但是在下面的代码中,-delegateMethod未被调用。 我想这是因为\u childViewController已经发布了。 如何修复它以使run-delegateMethod ContainerViewController.h @protocol ContainerViewDelegate <NSObject> - (void)delegateMe

ContainerViewController
将方法
-delegateMethod
委托给
ChildViewController

但是在下面的代码中,
-delegateMethod
未被调用。
我想这是因为
\u childViewController
已经发布了。
如何修复它以使run
-delegateMethod

ContainerViewController.h

@protocol ContainerViewDelegate <NSObject>

- (void)delegateMethod;

@end

@interface ContainerViewController : UIViewController

@property (nonatomic, assign) id<ContainerViewDelegate> delegate;

@end
ChildViewController.m

@interface ContainerViewController () {
    ChildViewController *_childViewController;
}

//...

- (void)viewDidLoad
{
    _childViewController = [[WeeklyViewController alloc]init];
    [self addChildViewController:_childViewController];
    [self.view addSubview:_childViewController.view];
    [_childViewController didMoveToParentViewController:self];
}

- (void)buttonAction {
    [self.delegate delegateMethod];
}
@interface ChildViewController () <ContainerViewDelegate>

//...

- (void)delegateMethod {
    NSLog(@"succeed!");
}
@接口ChildViewController()
//...
-(作废)委托方法{
NSLog(@“成功!”);
}

您从未设置委托,因此self.delegate将为零。你应该这样做

    - (void)viewDidLoad
{
    _childViewController = [[WeeklyViewController alloc]init];
    self.delegate = _childViewController;
    [self addChildViewController:_childViewController];
    [self.view addSubview:_childViewController.view];
    [_childViewController didMoveToParentViewController:self];
}

您从未设置委托,因此self.delegate将为零。你应该这样做

    - (void)viewDidLoad
{
    _childViewController = [[WeeklyViewController alloc]init];
    self.delegate = _childViewController;
    [self addChildViewController:_childViewController];
    [self.view addSubview:_childViewController.view];
    [_childViewController didMoveToParentViewController:self];
}

您从未设置委托,因此self.delegate将为零。你应该这样做

    - (void)viewDidLoad
{
    _childViewController = [[WeeklyViewController alloc]init];
    self.delegate = _childViewController;
    [self addChildViewController:_childViewController];
    [self.view addSubview:_childViewController.view];
    [_childViewController didMoveToParentViewController:self];
}

您从未设置委托,因此self.delegate将为零。你应该这样做

    - (void)viewDidLoad
{
    _childViewController = [[WeeklyViewController alloc]init];
    self.delegate = _childViewController;
    [self addChildViewController:_childViewController];
    [self.view addSubview:_childViewController.view];
    [_childViewController didMoveToParentViewController:self];
}

_未释放childViewController。当您将ContainerViewController作为子控件添加时,它得到了一个指向它的强指针。\u childViewController未被释放。当您将ContainerViewController作为子控件添加时,它得到了一个指向它的强指针。\u childViewController未被释放。当您将ContainerViewController作为子控件添加时,它得到了一个指向它的强指针。\u childViewController未被释放。当您将ContainerViewController作为子项添加时,它得到了一个指向它的强指针。