我需要显示一个视图控制器并拥有当前代码:
SavedFiles *savedFilesVC = [[[SavedFiles alloc] init] autorelease];
[self presentModalViewController:savedFilesVC animated:YES];
虽然它出现了这个错误:
2011-09-12 18:38:45.808 iDHSB[248:707] -[iDHSB_MobileAppDelegate presentModalViewController:animated:]: unrecognized selector
sent to instance 0x1bb880
2011-09-12 18:38:45.825 iDHSB[248:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-
[iDHSB_MobileAppDelegate presentModalViewController:animated:]: unrecognized selector sent to instance 0x1bb880'
*** Call stack at first throw:
(
0 CoreFoundation 0x3583064f __exceptionPreprocess + 114
1 libobjc.A.dylib 0x36583c5d objc_exception_throw + 24
2 CoreFoundation 0x358341bf -[NSObject(NSObject) doesNotRecognizeSelector:] + 102
3 CoreFoundation 0x35833649 ___forwarding___ + 508
4 CoreFoundation 0x357aa180 _CF_forwarding_prep_0 + 48
5 iDHSB 0x00007671 -[iDHSB_MobileAppDelegate actionSheet:clickedButtonAtIndex:] + 140
6 UIKit 0x3203c03d -[UIActionSheet(Private) _buttonClicked:] + 192
7 CoreFoundation 0x357a0571 -[NSObject(NSObject) performSelector:withObject:withObject:] + 24
8 UIKit 0x31f39ec9 -[UIApplication sendAction:to:from:forEvent:] + 84
9 UIKit 0x31f39e69 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 32
10 UIKit 0x31f39e3b -[UIControl sendAction:to:forEvent:] + 38
11 UIKit 0x31f39b8d -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 356
12 UIKit 0x31f3a423 -[UIControl touchesEnded:withEvent:] + 342
13 UIKit 0x31f38bf5 -[UIWindow _sendTouchesForEvent:] + 368
14 UIKit 0x31f3856f -[UIWindow sendEvent:] + 262
15 UIKit 0x31f21313 -[UIApplication sendEvent:] + 298
16 UIKit 0x31f20c53 _UIApplicationHandleEvent + 5090
17 GraphicsServices 0x31df7e77 PurpleEventCallback + 666
18 CoreFoundation 0x35807a97 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 26
19 CoreFoundation 0x3580983f __CFRunLoopDoSource1 + 166
20 CoreFoundation 0x3580a60d __CFRunLoopRun + 520
21 CoreFoundation 0x3579aec3 CFRunLoopRunSpecific + 230
22 CoreFoundation 0x3579adcb CFRunLoopRunInMode + 58
23 GraphicsServices 0x31df741f GSEventRunModal + 114
24 GraphicsServices 0x31df74cb GSEventRun + 62
25 UIKit 0x31f4bd69 -[UIApplication _run] + 404
26 UIKit 0x31f49807 UIApplicationMain + 670
27 iDHSB 0x0000232d main + 48
28 iDHSB 0x000022f8 start + 40
)
terminate called after throwing an instance of 'NSException'
[Switching to process 11779 thread 0x0]
为什么会这样?
我需要做什么?
谢谢,
詹姆斯
答案 0 :(得分:3)
试试这个
[self.navigationController pushViewController:viewController animated:YES];
或
[self.view addsubview.viewcontroller.view];
答案 1 :(得分:2)
你需要在你的AppDelegate中加载第一个ViewController:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Add the navigation controller's view to the window and display
self.window.rootViewController = myController;
[self.window makeKeyAndVisible];
return YES;
}
在MainWindow.xib文件中(通常)加载和初始化视图控制器。你不能从AppDelegate调用presentModalViewController,你不能只是初始化你的控制器,在大多数情况下你需要initFromNib ..
答案 2 :(得分:1)
您不能直接从AppDelegate使用presentModalViewController:animated:
。它必须来自UIViewController
的实例。这是错误的原因。
答案 3 :(得分:1)
[[iDHSB_MobileAppDelegate mainViewController] presentModalViewController:savedFilesVC animated:YES]
你需要为ex mainViewController创建一个UIViewController说明并将其连接到xib。