我有一个加载 2 个 UIViewControllers 的 UITabBarController:一个地图和一个表格。单击 tabBarItem 时,我会捕获该事件并在目标视图上设置一些属性:
- (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-06-27 15:09:18.624 Billboard[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];
}
}
}