2011-12-24 38 views
1

應用程序打開時,我打電話給一個UIAlertView中第一件事情,我得到的錯誤Applications are expected to have a root view controller at the end of application launch錯誤:應用程序預計將有在應用程序啓動的最後一個根視圖控制器

任何想法,爲什麼會發生這種情況

- (void)viewDidLoad 
{ 
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; 
if([userDefaults stringForKey:@"kUserName"] == nil) 
{ 
    NSLog(@"enter a username"); 
    askForUserName = [[UIAlertView alloc] initWithTitle:@"First time here I see!" 
                  message:@"Please enter a username:\n\n" 
                  delegate:self 
                  cancelButtonTitle:@"Done" 
                  otherButtonTitles:nil]; 


    CGRect frame = CGRectMake(48, 70, 200, 20); 
    usernameField = [[UITextField alloc] initWithFrame:frame]; 
    usernameField.placeholder = @"Username";   
    usernameField.backgroundColor = [UIColor whiteColor];  
    usernameField.autocorrectionType = UITextAutocorrectionTypeDefault;   
    usernameField.keyboardType = UIKeyboardTypeAlphabet;   
    usernameField.returnKeyType = UIReturnKeyDefault; 
    usernameField.clearButtonMode = UITextFieldViewModeWhileEditing; 
    [askForUserName addSubview:usernameField]; 

    [askForUserName show];   


} else 
{ 
    userName = [userDefaults stringForKey:@"kUserName"]; 
} 

// Do any additional setup after loading the view, typically from a nib. 
} 

回答

3

我注意到這也發生在我的一個應用程序中。我想這是因爲UIAlertViews阻止了應用程序啓動的主線程。我從來沒有遇到任何實際的問題(它不會崩潰應用程序或任何東西),但你可以嘗試用NSTimer和塊/不同線程延遲調用它來移除警告。

1

這通常是由於缺少連接窗口& view-controller.Just檢查您是否在Interface Builder中進行了正確的連接。希望它應該有所幫助。

相關問題