我在AppDelegate.m文件中设置了UIAlertView。
但是当我选择警报视图上的按钮时。
-(void) alertView:(UIAlertView *) alertView clickedButtonAtIndex:(NSInteger)buttonIndex不起作用。
我在AppDelegate.h文件中设置了UIAlertViewDelegate。
和我的助理代表。
- (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没有输入此方法。
有人知道发生了什么吗?谢谢。
发布于 2014-06-23 02:54:32
您的代码没有正确设置警报视图的委托。
您需要更改以下行,以便委托是适当的对象(例如,self):
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:@"my message" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:@"set",nil];发布于 2014-06-23 04:42:49
你必须更换线路
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:@"my message" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:@"set",nil];
[alertView show];由这一行
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:@"my message" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:@"set",nil];
[alertView show];要调用委托方法,必须将委托设置为self。
发布于 2014-06-23 04:25:38
检查.h文件中的委托引用。戴上UIAlertViewDelegate。
@interface YourViewController : UIViewController<UIAlertViewDelegate>https://stackoverflow.com/questions/24357810
复制相似问题