【发布时间】:2012-02-06 16:06:18
【问题描述】:
我正在开发一个小型应用程序,根据要求,该应用程序应该有一个包含 3 个项目的 tabBarItem。为此,我以编程方式在 AppDelegate.m 文件中创建了 tabBarController,并添加了 3 个不同的 viewController,将它们实例化,一切正常。我看到 tabBarItems 并且所有视图都在工作。在其中一个视图中,让我们说 SecondViewController 我展示了一个 popOverController,我在其中使用了 UITableView 并用项目填充它。当我单击其中一个项目时,它应该显示另一个视图,比如说 sendFeedback。直到一切正常,但是一旦这个 sendFeedback 显示为模态视图,它就会占据整个应用程序,即它隐藏了 tabBarItem。
我在这里展示重要的代码片段以供审查:
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];
}
谁能指导我如何通过多个视图来克服这个问题。如果有人需要我方面的更多信息,我很乐意提供。
注意:与其他视图(下载)相同
编辑:这是我在 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];
}
谢谢
【问题讨论】:
标签: objective-c ipad ios5 xcode4.2