打开应用程序时,我首先调用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.
}
最佳答案
我也注意到这是在我的一个应用程序中发生的。我认为这是因为UIAlertViews阻止了触发应用程序的主线程。我从来没有任何实际的问题(它不会使应用程序或任何应用程序崩溃),但是您可以尝试在延迟后使用NSTimer和阻塞/不同线程来调用它,以消除警告。
关于objective-c - 错误:在应用程序启动结束时,应用程序应具有根 View Controller ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8626395/