2011-03-27 6 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' 
  • データベースは、たぶん私はその方法でそのアクションを行うことはできませんnilを

ではありません。知るか。どんな助けもありがとう!
クールトン!

答えて

1

すべてsleep(5);の最初には、メインスレッド上で睡眠を使用しないでください(と、より良いどこでもそれを使用しないでください)、悪い考えです。

を使用すると、1つのファイル(メインアプリデリゲート)ですべてのコードを持っており、それはまた、テーブルビューのデリゲートであるようですか?なぜそんなに乱雑なコードがあるのか​​、2つのグループで論理を分けてみてください。

たとえば、ナビゲーションコントローラの助けを借りて、あなたのモーダルビュー表示することができます:

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

をとiOSで

[self.navigationController dismissModalViewControllerAnimated:YES]; 

を使用して、それを閉じ、あなたはコントローラを提示することによって、ビューをモーダル表示することができますあなたの現在のビューコントローラからのモーダルビューのために。だからあなたは以前にロードされたView Controllerを取得しています。

+0

ありがとうございました!そして、はい、私はそれが2つの場所にあることを認識しています。私はそれを移動していて、他の場所でそれを削除しようとしていました。 – iosfreak

関連する問題