Thursday, 22 August 2013

Objective-C/UIAlertView - I can't find the button pressed in the alert view

Objective-C/UIAlertView - I can't find the button pressed in the alert view

For the program that i'm developing, i have created a class "Utilities"
that contains an alert view with a cancel button. I want create one NSLog
that advice me when the cancel button is pressed. The method that contains
the alert view is called in another class, that is the ViewController.m
file, but at the moment no log appear. Can you please help me to
understand what i'm doing wrong?
This is the Utilities.h file:
@interface Utilities : UIViewController <UIAlertViewDelegate>
-(Boolean) isOnline;
-(void) buttonPressed;
@end
This is the Utilities.m file:
-(Boolean) isOnline {
Boolean online = false;
Reachability *reachability = [Reachability
reachabilityForInternetConnection];
[reachability startNotifier];
NetworkStatus status = [reachability currentReachabilityStatus];
if(status == ReachableViaWiFi)
{
NSLog(@"WI FI");
online = true;
}
else
{
NSLog(@"NO WI FI");
UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Warning"
message:@"You are
not connected to a
wireless network.
Please connect your
device."
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[message show];
}
return online;
}
- (void) buttonPressed:(UIAlertView *)alert
clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex==0) {
NSLog(@"Clicked the button Ok");
}
}
And here is where i call the method in the "ViewController" class:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
//Add gradient background
CAGradientLayer *bgLayer = [BackgroundLayer blueGradient];
bgLayer.frame = self.view.bounds;
[self.view.layer insertSublayer:bgLayer atIndex:0];
[self initialize];
Utilities* utilities = [[Utilities alloc] init]; //create an istance of
the class Utilities for use their methods in this class
[utilities isOnline]; //call the method isOnline from the class Utilities
}
Thanks

No comments:

Post a Comment