我有一个UITabBarController加载2 UIViewControllers:地图和表。当单击tabBarItem,我赶上事件,并在目标视图中的某些属性:UITabBarController和UIViewController转换
- (void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
if([viewController.tabBarItem.title isEqualToString:@"Map"]) {
MapViewController *MVC = [tabBarController.childViewControllers objectAtIndex: viewController.tabBarController.selectedIndex];
MVC.billboards = self.billboards;
MVC.rangeMaxWidth = self.rangeMaxWidth;
MVC.rangeMaxHeight = self.rangeMaxHeight;
MVC.APIRoot = self.APIRoot;
}
}
现在上面的代码的伟大工程;然而,当我尝试为我的表格视图做同样的事情时,我得到一个神秘的错误。下面是全码:
- (void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
if([viewController.tabBarItem.title isEqualToString:@"Map"]) {
MapViewController *MVC = [tabBarController.childViewControllers objectAtIndex: viewController.tabBarController.selectedIndex];
MVC.billboards = self.billboards;
MVC.rangeMaxWidth = self.rangeMaxWidth;
MVC.rangeMaxHeight = self.rangeMaxHeight;
MVC.APIRoot = self.APIRoot;
} else if ([viewController.tabBarItem.title isEqualToString:@"Manage"]) {
ManageBillboardsController *MBC = [tabBarController.childViewControllers objectAtIndex: viewController.tabBarController.selectedIndex];
MBC.aNumber = [[NSNumber alloc] initWithInt:3];
}
}
- [UINavigationController的setANumber:]:无法识别的选择发送到实例0x9e91400 2013年6月27日15:09:18.624广告牌[3269:C07] *终止应用程序由于未捕获的异常“NSInvalidArgumentException”,原因:' - [UINavigationController setANumber:]:无法识别的选择器发送到实例0x9e91400'
我想我已经双重检查了一切,两个视图似乎都一样。所以我不明白为什么这适用于地图视图,但不适用于表格。
在此先感谢。
*解*
- (void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
if([viewController.tabBarItem.title isEqualToString:@"Map"]) {
MapViewController *MVC = [tabBarController.childViewControllers objectAtIndex: viewController.tabBarController.selectedIndex];
MVC.billboards = self.billboards;
MVC.rangeMaxWidth = self.rangeMaxWidth;
MVC.rangeMaxHeight = self.rangeMaxHeight;
MVC.APIRoot = self.APIRoot;
} else if ([viewController.tabBarItem.title isEqualToString:@"Manage"]) {
UINavigationController *NC = [tabBarController.childViewControllers objectAtIndex: viewController.tabBarController.selectedIndex];
NSArray *controllers = [NC childViewControllers];
for(id item in controllers){
ManageBillboardsController *MBC = item;
MBC.aNumber = [[NSNumber alloc] initWithInt:3];
}
}
}
嗯我认为你是正确的,但我没有明确定义这个导航控制器在任何地方,即:.h文件中没有变量。我应该从哪里开始寻找? –
您的故事板或XIB? – Danilo
好的你的建议让我走上正确的道路。我将在此主题中添加一篇文章,展示解决方案。谢谢! –