I am making an app where if the webpage doesnt load, it gives an error and returns to the previous screen. However, in doing this, after all the code, get an undeclared identifier
#pragma mark - View lifecycle
- (void)viewDidLoad
{
UIAlertView *cats = [[UIAlertView alloc] initWithTitle:@"**Read this first!**"
message:@"Thank you for ..."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[cats show];
[catscroll setScrollEnabled:YES];
[catscroll setContentSize:CGSizeMake(320,4800)];
[catscroll setPagingEnabled:NO];
[catform loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://m.petfinder.com/s/showPage.do?siteId=76333&pageId=7133416&shelterId=MA84&navigateToPage=Adopt%20Pets"]]];
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)doPop
{
[cats dissmissWithClickedButtonIndex:-1 animated:YES];
[self.navigationController popViewControllerAnimated:YES];
UIAlertView *noconnectcatform = [[UIAlertView alloc] initWithTitle:@"Check your connection!"
message:@"Cannot connect to FPP Servers.\nPlease check your Internet Connection\nYou may not proceed until you are connected via a cellular network."
delegate:nil cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[noconnectcatform show];
}
as you can see in this image. If the webpage doesnt load it activates doPop, which returns the view and displays a message. However, this is throwing an EXC_BAD_ACCESS because, as you can see, under the viewDidLoad method, there is another message that plays. The app is getting confused and crashing. I tried to fix this by dismissing the alert in the doPop method, however it is strangely giving me this error. I may be misunderstanding, but isn’t the alertview defined where it says “UIAlertView *cats”? why does it say that it is not defined in the doPop method? Please help!
The object
catsis defined locally toviewDidLoad. The scope of the variable does not extend beyond the method, thusdoPophas no idea what cats is.Move
catsto be defined in the .h file as a member/class variable.This means you’ll need to remove the
UIAlertView *from withinviewDidLoadand just reference cats (as is, you are defining another variable scoped toviewDidLoad).You have a typo in the method called in
doPopThe method isdismissWithClickedButtonIndex:1 animated:YES];You havedissmissWithClickedButtonIndex:1 animated:YES];Also, you only need
IBOutletdefined with the@property