2015-09-28 23 views
1

我想通过使用Objective-C将数据从我的ViewController传递到TabBarController。我试图将一些数据分配给“bottomTabEventList”(这是我的自定义TabBarController类的属性)。不幸的是,我的程序因给出无法识别的选择器实例错误/警告而崩溃。prepareForSegue为TabBarController

在TabBarController类的自定义标题,名为BottomTabview:

@interface BottomTabView : UITabBarController <UITabBarControllerDelegate> 

@property(strong,nonatomic)EventList *bottomTabEventList; 

@end 

而且在ViewController.m prepareForSegue方法

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
    BottomTabView *btw = [segue destinationViewController]; 

    //checking 
    if(btw == nil) 
     NSLog(@"btw in viewController is nil"); 
    else 
     NSLog(@"btw in viewController is NOT nil"); 

    if(self.eventList.eventList == nil) 
     NSLog(@"eventList in viewController is nil"); 
    else 
     NSLog(@"eventList in viewController is NOT nil"); //end of checking 

    btw.bottomTabEventList = self.eventList; //This is where crash appears 
} 

精确崩溃日志是:

- [视图控制器setBottomTabEventList :]:无法识别的选择器发送到实例0x7fe923c6ba00 * **终止应用程序由于未捕获的异常“NSInvalidArgumentException”,原因:“ - [视图控制器setBottomTabEventList:]:无法识别的选择发送到实例0x7fe923c6ba00”

Segue公司是从视图控制器到BottomTabView,其类型是“Present模态”。如果你能帮助/指导我,我会很感激。提前致谢。

+0

尝试投这样的:BottomTabView * BTW =(BottomTabView *)[Segue公司destinationViewController] – kirander

+0

这只是铸造,并有助于沉默编译器警告。如果destinationViewController不是一开始,它不会神奇地使btw成为BottomTabView类。 – Tander

回答

0

这个问题似乎是btw实际上不是BottomTabView类型,并且仅仅是一个UIViewController因此崩溃日志,并提供:

[视图控制器setBottomTabEventList:]:无法识别的选择发送到实例

由于UIViewController不知道BottomTabEventList是什么。

您需要确保btw实际上是一个BottomTabView实例。

做一点点的反省,我敢打赌,它不会进入这样的说法:

if ([btw isKindOfClass:[BottomTabView class]]){ 
btw.bottomTabEventList = self.eventList; 
}