我正在尝试使用Robert Ryan制作的Edge Swipe Demonstration课程 https://github.com/robertmryan/edge-swipe-demonstration
当我使用我制作的newcontroller更改firstviewcontroller时使用它 它在NSAssert线上显示我的错误
这是EdgeSwipeSegue.m代码
@implementation EdgeSwipeSegue
- (void)perform
{
UIViewController *source = self.sourceViewController;
id <ParentControllerDelegate>parent = (id)source.parentViewController;
if(parent==nil){
NSLog(@"Parent is nil");
}
NSAssert([parent conformsToProtocol:@protocol(ParentControllerDelegate)], @"Parent does not conform to ParentControllerDelegate; parent = %@", parent);
[parent pushChildViewController:self.destinationViewController];
}
我有BarButton,我拖到secondviewcontroller并选择了edgeSegue,但也许我错过了一些东西
为什么断言失败?
答案 0 :(得分:0)
让我们试试:
// I assume that you have NewViewController
// in NewViewController.h
@interface NewViewController : UIViewController < ParentControllerDelegate >
//in NewViewController.m : just implement method is declared in ParentControllerDelegate
答案 1 :(得分:0)
好的,我自己找到了答案
我有这个雇佣军
- ParentViewController(ContainerView)
- NavigationController
- Viewcontroller
所以这个id parent =(id)source.parentViewController;给了我navigationviewcontroller而不是我需要的parentviewcontroller
所以像这样解决了
UIViewcontroller *cont = self.sourceViewController;
UIViewController *source = con.navigationController;
并且有效