@implementation AppDelegate
– (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
ViewController1 *v1=[[ViewController1 alloc]init];
UINavigationController *navation=[[UINavigationController alloc]initWithRootViewController:v1];
navation.title=@”首页”;
ViewController2 *v2=[[ViewController2 alloc]init];
UITabBarItem *item2=[[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemBookmarks tag:1];
v2.tabBarItem=item2;
ViewController3 *v3=[[ViewController3 alloc]init];
UITabBarItem *item3=[[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemBookmarks tag:2];
v3.tabBarItem=item3;
NSArray *viewcontrols=[[NSArray alloc]initWithObjects:navation,v2,v3,nil];
UITabBarController *tabcotrollers=[[UITabBarController alloc]init];
tabcotrollers.selectedViewController=v2;
tabcotrollers.tabBar.tintColor=[UIColor greenColor];
tabcotrollers.viewControllers=viewcontrols;
self.window.rootViewController=tabcotrollers;
错误如下:
Terminating app due to uncaught exception “”NSInvalidArgumentException””, reason: “”-[UITabBarController setSelectedViewController:] only a view controller in the tab bar controller””s list of view controllers can be selected.””
*** First throw call stack:
(
0 CoreFoundation 0x017ee1e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x0156d8e5 objc_exception_throw + 44
2 CoreFoundation 0x017edfbb +[NSException raise:format:] + 139
3 UIKit 0x0037facc -[UITabBarController setSelectedViewController:] + 180
4 UItabBarItem 0x00002d39 -[AppDelegate application:didFinishLaunchingWithOptions:] + 1241
5 UIKit 0x0022714f -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 309
6 UIKit 0x00227aa1 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1810
7 UIKit 0x0022c667 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 824
8 UIKit 0x00240f92 -[UIApplication handleEvent:withNewEvent:] + 3517
9 UIKit 0x00241555 -[UIApplication sendEvent:] + 85
10 UIKit 0x0022e250 _UIApplicationHandleEvent + 683
11 GraphicsServices 0x037e3f02 _PurpleEventCallback + 776
12 GraphicsServices 0x037e3a0d PurpleEventCallback + 46
13 CoreFoundation 0x01769ca5 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
14 CoreFoundation 0x017699db __CFRunLoopDoSource1 + 523
15 CoreFoundation 0x0179468c __CFRunLoopRun + 2156
16 CoreFoundation 0x017939d3 CFRunLoopRunSpecific + 467
17 CoreFoundation 0x017937eb CFRunLoopRunInMode + 123
18 UIKit 0x0022bd9c -[UIApplication _run] + 840
19 UIKit 0x0022df9b UIApplicationMain + 1225
20 UItabBarItem 0x000037cd main + 141
21 libdyld.dylib 0x01e35701 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
这个该怎么破?(xcode5.1 ios7的配置)