I am using a UIAlertView for entering username and password credentials before the next modal view, that gives him access to files in his account, appears.
However, when I debug, I came to know that the “ViewDidLoad” method of the modal view is called before the alertView shows up, and hence the program crashes as the view is not able to get username and password.
Here is the code
-(IBAction) openShareFile:(id)sender
{
if (!self.shareFileBrowser) {
self.shareFileBrowser=[[ShareFileBrowserViewController alloc] initWithNibName:@"ShareFileBrowserViewController" bundle:nil];
self.alertView = [[UIAlertView alloc] initWithTitle:@"Verify your Credentials" message:@"Enter Username & Password" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
self.alertView.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
[self.alertView show];
self.shareFileBrowser.domain=@"fidomoose";
self.shareFileBrowser.delegate=self;
self.shareFileBrowser.title=@"ShareFile Browser";
self.navController= [[UINavigationController alloc] initWithRootViewController:self.shareFileBrowser];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
self.popController = [[UIPopoverController alloc] initWithContentViewController:self.navController];
}
}
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
if ([self.popController isPopoverVisible]) {
[self.popController dismissPopoverAnimated:YES];
} else {
[self.popController presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
}
else {
[self presentModalViewController:self.navController animated:YES];
}
}
Just put your code for init of your view in the delegate method of
UIAlertViewlike followEDIT:1
Just use the method
presentPopoverFromRect:instead ofpresentPopoverFromBarButtonItem:and give properCGRectivar instead ofsenderThis will definitely solve your problem 🙂