好的,所以苹果在 iOS 5 中引入了视图控制器容器(太棒了!)
以上是我的应用层的样子。TabBar 包含 NavController 包含 ViewController(容器),它包含 2 个表视图,由分段控件切换。
当我选择一个表格单元格时,它会轻松推送新视图。但是,如果我在 detailViewController 中按下一个按钮,我希望它以模态方式显示 MFMailComposeViewController。它短暂地呈现自己,然后立即消失。我得到的错误日志是:
对 UITabBarController 的开始/结束外观转换的不平衡调用
现在,这意味着我试图在另一个视图仍在显示或在运行时循环中时呈现一个视图,我尝试添加延迟来阻止它,但没有任何效果。我已经添加了我的所有代表,并正确导入了我的所有库。
我认为这可能与我如何从原始 tableview 推送新视图或如何将视图加载到容器中有关。该项目使用 Xcode 的 Tab Bar 应用程序模板的基本代码,如您所知。这是代码:
视图控制器/容器
- (void)viewDidLoad
{
[super viewDidLoad];
// Alloc Init View Controllers
menuDrinksViewController = [[MenuDrinksViewController alloc] init];
menuFoodViewController = [[MenuFoodViewController alloc] init];
// Create Parent/Child relationship
[menuFoodViewController didMoveToParentViewController:self];
[self addChildViewController:menuFoodViewController];
[menuDrinksViewController didMoveToParentViewController:self];
[self addChildViewController:menuDrinksViewController];
[appearanceClass setBackgroundImage:self.view];
// segmented controller
segmentedControl = [[SVSegmentedControl alloc] initWithSectionTitles:[NSArray arrayWithObjects:@" Eat ", @" Drink ", nil]];
[segmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
[appearanceClass setSegmentedControl:segmentedControl];
[self.view addSubview:segmentedControl];
//self.view.backgroundColor = [UIColor redColor];
// Add and Size subviews
[self.view addSubview:menuFoodViewController.view];
menuFoodViewController.view.frame = CGRectMake(0, 39, 320, self.view.frame.size.height - 40 + 1);
menuDrinksViewController.view.frame = CGRectMake(0, 39, 320, 327 + 1);
}
-(IBAction)segmentAction:(id)selector
{
// it's a custom segmented control, dw bout the code.
if (segmentedControl.selectedIndex == 0)
{
[self.view addSubview:menuFoodViewController.view];
[menuDrinksViewController.view removeFromSuperview];
}
else if (segmentedControl.selectedIndex == 1)
{
[self.view addSubview:menuDrinksViewController.view];
[menuFoodViewController.view removeFromSuperview];
}
}
表视图控制器
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
MenuFoodDetailViewController *menuFoodDetailViewController = [[MenuFoodDetailViewController alloc] initWithNibName:nil bundle:nil];
//MenuFoodDetailViewController *menuFoodDetailViewController = [[MenuFoodDetailViewController alloc] init];
[self.parentViewController.navigationController pushViewController:menuFoodDetailViewController animated:YES];
[tableView deselectRowAtIndexPath:indexPath animated:NO];
}
来自详细视图控制器的 ButtonPress 代码。
- (void)showMailComposer
{
// attempt to delay the presentModalView call, doesnt work...
double delayInSeconds = 0.1;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[self.navigationController presentModalViewController:mailComposeViewController animated:YES];
});
}
我知道这有很多问题要问,但我已经在这个问题上待了好几天了。所有与视图无关的代码,即 MFMailViewComposer 工作正常,我已经在其他应用程序中对其进行了测试。
我已经尝试了各种变化来推动新的模态视图,即
self.parentViewController.navigationController presentModal...
(等)
什么都没有工作=/