2012-02-06 51 views
1

我正在一个小应用程序,根据要求应用程序应该有一个tabBarItem与3项。为此,我以编程方式在AppDelegate.m文件中创建了tabBarController,并添加了3个不同的viewController,对它们进行了实例化,并且一切都很好。我看到tabBarItems和所有视图正在工作。在其中一个视图让我们说在SecondViewController中,我显示了一个popOverController,其中我使用了一个UITableView并用项目填充它。当我点击其中一个项目时,它应该显示另一个视图让我们说sendFeedback。直到那里一切工作正常,但只要此sendFeedback呈现为模式视图,它占据了整个应用程序,即隐藏tabBarItem。UITabBarController与UIPopOverController与多个视图

我在这里介绍的代码的重要棋子审查:

AppDelegate.m

- (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]; 

} 

任何人都可以指导我如何克服这与多个意见。如果有人需要我的更多信息,我会很乐意提供。

注:这是与其他视图(下载)以及

编辑同:这里是我如何初始化我PopOverController在AppDelegate.m文件

- (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];   
    } 

感谢

回答

0

模态视图控制器用于“阻止”您的应用程序并完成任务,然后才能继续。所以模态视图控制器不是你想要使用的。

将您的控制器包含在导航控制器的弹出窗口中。在tableView:didSelectRowAtIndexPath:方法中,您可以将相应的视图控制器推送到导航堆栈。

为了解决您的问题: 在您创建popovercontroller的地方使用新的UINavigationController对其进行初始化。导航控制器必须使用rootviewcontroller(即PopOverViewController.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]; 
+0

嗨,多米尼克感谢指出。是否有任何使用此导航堆栈的示例,正​​如我所说的,我刚开始使用ios的东西。所以,如果有一些例子,将有助于一个例子。 – 125369 2012-02-07 10:00:54

+0

我强烈建议你阅读[苹果视图控制器编程指南](https://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/Introduction/Introduction.html)。这对iOS开发非常重要,所以请花时间仔细阅读它 - 这是值得的。 – Dominik 2012-02-07 10:10:50

+0

嗨,多米尼克,多数民众赞成你给一小段代码,但我得到一个SIGABRT错误,当我点击应显示PopOverControl的TabBarItem。您能否推荐适合我的代码的必要更改。谢谢 – 125369 2012-02-07 12:12:19

相关问题