我正在尝试将Tabs实现到我的secondView.On按钮触摸(来自ViewController.m)我正在导航到secondView(Tabs)。在我的Tabs.xib
文件中,我在底部添加了一个TabBar,它是自定义类UITabBar
。
ViewController.m
- (IBAction)touchedInside:(id)sender {
NSLog(@"touhced up inside");
Tabs *temp = [[Tabs alloc]initWithNibName:@"Tabs" bundle:nil];
[self.navigationController pushViewController:temp animated:YES];
[self presentViewController:temp animated:YES completion:nil];
}
Tabs.m
- (void)viewDidLoad
{
[super viewDidLoad];
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
UITabBarController *tabBarController = [[UITabBarController alloc]init];
/*
Tab_1 *firstView = [[Tab_1 alloc] init];
UITabBarItem *item1 = [[UITabBarItem alloc]initWithTitle:@"First" image:nil tag:1];
[firstView setTabBarItem:item1];
NSLog(@"after first tab is added");
Tab_2 *secondView = [[Tab_2 alloc] init];
UITabBarItem *item2 = [[UITabBarItem alloc]initWithTitle:@"Sec" image:nil tag:1] ;
[secondView setTabBarItem:item2];
NSLog(@"after second tab is added");
[tabBarController setViewControllers:[NSArray arrayWithObjects:firstView,secondView,nil] animated:NO];
NSLog(@"after tab is added");
[appDelegate.window addSubview:tabBarController.view];
NSLog(@"after view is added");
*/
appDelegate.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UIViewController *viewController1 = [[Tab_1 alloc] initWithNibName:@"Tab 1" bundle:nil];
UIViewController *viewController2 = [[Tab_2 alloc] initWithNibName:@"Tab 2" bundle:nil];
UIViewController *viewController3 = [[Tab_2 alloc] initWithNibName:@"Tab 1" bundle:nil];
tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, viewController3, nil];
appDelegate.window.rootViewController = self.tabBarController;
[appDelegate.window makeKeyAndVisible];
Tabs *temp = [[Tabs alloc]initWithNibName:@"Tabs" bundle:nil];
[self.navigationController presentModalViewController:temp animated:NO];
}
错误
Unbalanced calls to begin/end appearance transitions for <ViewController: 0x6833c80>.
2012-12-06 09:57:48.963 demoTabs[667:f803] Unbalanced calls to begin/end appearance transitions for <Tabs: 0x6a3fc90>.
答案 0 :(得分:0)
Tab_1 *viewController1 = [[Tab_1 alloc] initWithNibName:@"Tab 1" bundle:nil]; Tab_2 *viewController2 = [[Tab_2 alloc] initWithNibName:@"Tab 2" bundle:nil]; Tab_2 *viewController3 = [[Tab_2 alloc] initWithNibName:@"Tab 1" bundle:nil];
定义上面定义的viewcontroller实例,同时确保为每个viewcontroller提供coorect nib文件名。