Objective c 带多视图UIPopOverController的UIAbbarController
我正在开发一个小应用程序,根据要求,该应用程序应该有一个包含3项的tabBarItem。为此,我在AppDelegate.m文件中以编程方式创建了tabBarController,并添加了3个不同的viewcontroller,对它们进行了实例化,一切正常。我看到tabBarItems和所有视图都在工作。在其中一个视图中,假设在SecondViewController中,我显示了一个popOverController,其中我使用了UITableView并用项目填充它。当我点击其中一个项目时,它会显示另一个视图,比如sendFeedback。在此之前,一切正常,但一旦此sendFeedback显示为模态视图,它就会占据整个应用程序,即隐藏tabBarItem 我在这里介绍了一些重要的代码,以供审查: AppDelegate.mObjective c 带多视图UIPopOverController的UIAbbarController,objective-c,ipad,ios5,xcode4.2,Objective C,Ipad,Ios5,Xcode4.2,我正在开发一个小应用程序,根据要求,该应用程序应该有一个包含3项的tabBarItem。为此,我在AppDelegate.m文件中以编程方式创建了tabBarController,并添加了3个不同的viewcontroller,对它们进行了实例化,一切正常。我看到tabBarItems和所有视图都在工作。在其中一个视图中,假设在SecondViewController中,我显示了一个popOverController,其中我使用了UITableView并用项目填充它。当我点击其中一个项目时,它会
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
viewController1.title = @"First";
UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
viewController2.title = @"Second";
UITableViewController *tableView3 = [[tableViewController alloc]initWithNibName:@"tableViewController" bundle:nil];
tableView3.title = @"Third";
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, tableView3 ,nil];
self.tabBarController.delegate = self;
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
[viewController1 release];
[viewController2 release];
[tableView3 release];
return YES;
}
在我的popOverViewController.m文件中,我正在根据显示视图的内容检查表中选择了哪一行
#pragma mark - TableView Delegate Methods
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
sendFeedback *sendEmailViewController = [[sendFeedback alloc]initWithNibName:@"sendFeedback" bundle:nil];
downLoad *downloadFilelViewController = [[downLoad alloc]initWithNibName:@"downLoad" bundle:nil];
if (indexPath.row == 0)
[self presentModalViewController:sendEmailViewController animated:YES];
else
[self presentModalViewController:downloadFilelViewController animated:YES];
}
有谁能指导我如何用多个视图克服这个问题。如果有人需要我方提供更多信息,我很乐意提供
注意:与其他视图(下载)相同
编辑:下面是我在AppDelegate.m文件中初始化PopOverController的方法
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
if([viewController isKindOfClass:[SecondViewController class]]){
NSInteger index = [[self tabBarController] selectedIndex];
CGRect buttonFrame = [[[[[self tabBarController] tabBar] subviews] objectAtIndex:index+1] frame];
PopOverViewController *popoverView = [PopOverViewController new];
popoverView.contentSizeForViewInPopover = CGSizeMake(250, 85);
popover = [[UIPopoverController alloc]initWithContentViewController:popoverView];
NSLog(@"X:%f Y:%f",buttonFrame.origin.x,buttonFrame.origin.y);
[popover presentPopoverFromRect:buttonFrame inView:self.tabBarController.tabBar permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
}
感谢模态视图控制器用于“阻止”应用程序并在继续之前完成任务。因此,模态视图控制器不是您想要使用的 相反,将必须在popover中显示的控制器包装在导航控制器中。在tableView:didSelectRowAtIndexPath:method中,可以将相应的视图控制器推送到导航堆栈中 要解决您的问题: 在创建popovercontroller的位置,使用新的UINavigationController初始化它。导航控制器必须使用rootviewcontroller即popoviewController.m进行初始化
PopOverController *popoverContentController = [[PopOverController alloc] init];
UINavigationController *navcon = [[UINavigationController alloc] initWithRootViewController:popoverContentController];
popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContentController];
在PopOverController.m中
if (indexPath.row == 0)
[self.navigationController pushViewController:sendEmailViewController animated:YES];
else
[self.navigationController pushViewController:downloadFilelViewController animated:YES];
你好,多米尼克,谢谢你指出这一点。有没有使用这个导航堆栈的例子,正如我刚才说的,我刚刚开始使用ios的东西。如果有一些例子的话,举个例子会很有帮助。我强烈建议你阅读。这是iOS开发的基础,所以请花点时间仔细阅读,这是值得的。你好,多米尼克,你给了我一小段代码,真是太好了,但是当我点击TabBarItem时,我发现了一个SIGABRT错误,它应该显示PopOverControl。您能推荐适合我的代码的必要更改吗。谢谢您在哪里显示UIPopover?当用户触摸SecondViewController类中的第二个tabBarItem时,我会显示UIPopover。这就是我得到的错误“由于未捕获的异常'nsGenericeException'而终止应用程序”,原因:“内容视图控制器参数必须是其关联视图控制器层次结构的根。”