我正在使用警报视图在未连接互联网时提醒用户。我在警报视图中有两个按钮,它们似乎都不起作用。我已经在 .h 文件中实现了。我使用 NSLog 检查单击时它是否响应。它在控制台中响应,但在按下按钮时什么也不做。这是我的代码片段。
- (IBAction)startButton:(id)sender
{
if (![self connectedToNetwork])
{
UIAlertView *internetAlert = [[UIAlertView alloc] initWithTitle: @"Network Error!" message: @"You are not connected to the internet" delegate: self cancelButtonTitle: @"OK" otherButtonTitles: @"Open Settings", nil];
[internetAlert show];
}
}
- (void)alertView: (UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0)
{
NSLog(@"Ok clicked");
HomeViewController *blah = [self.storyboard instantiateViewControllerWithIdentifier:@"HomeViewController"];
[self.view addSubview: blah.view];
}
else if (buttonIndex == 1)
{
NSLog(@"Settings clicked");
[[UIApplication sharedApplication] openURL: [NSURL URLWithString:@"prefs:root=WIFI"]];
}
}
我使用 [self.contentView addSubview: blah.view] 因为我没有导航控制器。关于我做错了什么的任何想法