如果我按下第二个 UITabbarItem,我正在尝试打开一个 UIViewController。
这是我的第一个 ViewController 的代码。如果我按 UITabbarItem #1(标签 1),它会设置 Label.text。在 #2 我想切换到 secondViewController 并且(标签 2)它崩溃了。有谁知道为什么?第一个断点位于 UIStoryboard...(故事板称为:Main.storyboard)。感谢帮助
#import "ViewController.h"
#import "secondViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.tabBar.delegate = self;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{
switch (item.tag) {
case 1: self.testlabel.text =@"test";
break;
case 2:
{ // create the Storyboard object
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
secondViewController *second = [storyboard instantiateViewControllerWithIdentifier:@"secondview"];
[self.navigationController pushViewController:second animated:YES];
}
break;
default: break; }
}
@end