2011-03-27 96 views
0

我正在製作一個帶有登錄功能的iPhone應用程序。他們登錄後,我把它寫入數據庫。當用戶打開應用程序時,我希望它檢查是否要去應用程序或顯示UIView以供他們登錄。我有一些代碼,但它崩潰。那就是:在AppDelegate中切換視圖時出錯

- (void)applicationDidFinishLaunching:(UIApplication *)application {  
sleep(5); 
// Configure and show the window 
[window addSubview:[navigationController view]]; 
[window makeKeyAndVisible]; 
//[application setStatusBarStyle:UIStatusBarStyleBlackOpaque]; 

int checkLoginCount = 0; 
NSArray *checkLoginInfo = [database executeQuery:@"SELECT * FROM login WHERE id != '' or email != '' or password != ''"]; 
for (NSDictionary *checkLoginRow in checkLoginInfo) { 
    checkLoginCount++; 
} 

NSLog(@"alsdfjaldfksjalsdfjkas %d", checkLoginCount); 

if (checkLoginCount == 0) { 
    SplashPageViewController *screentwo = [[SplashPageViewController alloc] initWithNibName:@"splashPage" bundle:nil]; 
    //NSLog(@"aldjksflasdfjadksaldfjsaldksfj %@", screentwo); 
    screentwo.modalTransitionStyle = UIModalTransitionStyleCoverVertical; 
    [self presentModalViewController:screentwo animated:NO]; 
    [screentwo release]; 
} else { 
    splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, 320, 480)]; 
    splashView.image = [UIImage imageNamed:@"Default.png"]; 
    [window addSubview:splashView]; 
    [window bringSubviewToFront:splashView]; 
    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationDuration:0.5]; 
    [UIView setAnimationTransition:UIViewAnimationTransitionNone forView:window cache:YES]; 
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationDidStopSelector:@selector(startupAnimationDone:finished:context:)]; 
    splashView.alpha = 0.0; 
    //splashView.frame = CGRectMake(-60, -60, 440, 600); 
    [UIView commitAnimations]; 
} 
} 

而這裏的錯誤:

-[TableViewAppDelegate presentModalViewController:animated:]: unrecognized selector sent to instance 0x4e3e860 
TableView[15309:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[TableViewAppDelegate presentModalViewController:animated:]: unrecognized selector sent to instance 0x4e3e860' 
*** Call stack at first throw: 
(
0 CoreFoundation      0x00fccbe9 __exceptionPreprocess + 185 
1 libobjc.A.dylib      0x011215c2 objc_exception_throw + 47 
2 CoreFoundation      0x00fce6fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187 
3 CoreFoundation      0x00f3e366 ___forwarding___ + 966 
4 CoreFoundation      0x00f3df22 _CF_forwarding_prep_0 + 50 
5 TableView       0x00002b02 -[TableViewAppDelegate applicationDidFinishLaunching:] + 473 
6 UIKit        0x002e6253 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1252 
7 UIKit        0x002e855e -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 439 
8 UIKit        0x002f2db2 -[UIApplication handleEvent:withNewEvent:] + 1533 
9 UIKit        0x002eb202 -[UIApplication sendEvent:] + 71 
10 UIKit        0x002f0732 _UIApplicationHandleEvent + 7576 
11 GraphicsServices     0x0186fa36 PurpleEventCallback + 1550 
12 CoreFoundation      0x00fae064 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52 
13 CoreFoundation      0x00f0e6f7 __CFRunLoopDoSource1 + 215 
14 CoreFoundation      0x00f0b983 __CFRunLoopRun + 979 
15 CoreFoundation      0x00f0b240 CFRunLoopRunSpecific + 208 
16 CoreFoundation      0x00f0b161 CFRunLoopRunInMode + 97 
17 UIKit        0x002e7fa8 -[UIApplication _run] + 636 
18 UIKit        0x002f442e UIApplicationMain + 1160 
19 TableView       0x000027f6 main + 84 
20 TableView       0x00002799 start + 53 
21 ???         0x00000001 0x0 + 1 
) 
terminate called after throwing an instance of 'NSException' 
  • 數據庫不是零

也許我不能這樣做在該方法的操作。誰知道。任何幫助表示讚賞!
Coulton!

回答

1

首先sleep(5);是一個壞主意,你應該避免在主線程中使用睡眠(最好不要在任何地方使用它)。

似乎你有一個文件(主應用程序委託)的所有代碼,它也是一個tableview委託?這就是爲什麼你有這麼混亂的代碼,試圖分成兩組邏輯。

例如,你可以展示你的導航控制器的幫助下模態的觀點:

[[self navigationController] presentModalViewController:modalViewController animated:YES]; 

,並使用

[self.navigationController dismissModalViewControllerAnimated:YES]; 

在iOS系統中關閉它,你可以通過呈現控制器模態顯示視圖用於當前視圖控制器的模態視圖。所以你之前加載了任何視圖控制器。

+0

謝謝,它的工作!是的,我知道這是在兩個地方。我正在移動它,並打算在其他地方刪除它。 – iosfreak 2011-03-28 02:56:12