【发布时间】:2015-12-25 10:39:16
【问题描述】:
我正在尝试使用 Objective-C 将数据从 ViewController 传递到 TabBarController。我正在尝试将一些数据分配给“bottomTabEventList”(这是我的自定义 TabBarController 类的属性)。不幸的是,我的程序因给出无法识别的选择器实例错误/警告而崩溃。
在 TabBarController 类的自定义 header 中,命名为 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
}
确切的崩溃日志是:
-[ViewController setBottomTabEventList:]:无法识别的选择器发送到实例 0x7fe923c6ba00 *** 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[ViewController setBottomTabEventList:]:无法识别的选择器发送到实例 0x7fe923c6ba00”
Segue 是从 ViewController 到 BottomTabView,它的类型是“Present Modally”。如果您能帮助/指导我,我将不胜感激。提前致谢。
【问题讨论】:
-
尝试像这样投射:BottomTabView *btw = (BottomTabView *)[segue destinationViewController];
-
这只是强制转换,有助于消除编译器警告。如果destinationViewController 不是一开始的,它就不会神奇地使一个BottomTabView 类。
标签: ios objective-c xcode uiviewcontroller uitabbarcontroller