我在 AppDelegate.m 文件中设置了 UIAlertView。
但是当我选择警报视图上的按钮时。
-(void) alertView:(UIAlertView *) alertView clickedButtonAtIndex:(NSInteger)buttonIndex
没有工作。
我在 AppDelegate.h 文件中设置了 UIAlertViewDelegate。
和我的 AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(reachabilityChanged:)
name:kReachabilityChangedNotification
object:nil];
NSString *remoteHostName = REACHABILITY_HOST;
_hostReachability = [Reachability reachabilityWithHostName:remoteHostName];
[_hostReachability startNotifier];
return YES;
}
- (void) reachabilityChanged:(NSNotification *)note
{
if( [Reachability isExistNetwork] == NotReachable)
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:@"my message" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:@"set",nil];
[alertView show];
}
}
-(void) alertView:(UIAlertView *) alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
switch (buttonIndex) {
case 0:
NSLog(@"ok!");
break;
// set
case 1:
NSLog(@"set!");
NSURL*url=[NSURL URLWithString:@"prefs:root=WIFI"];
[[UIApplication sharedApplication] openURL:url];
break;
}
}
但是
-(void) alertView:(UIAlertView *) alertView clickedButtonAtIndex:(NSInteger)buttonIndex
没有进入这个方法。
有谁知道发生了什么?谢谢。