我最近开始研究 iOS 开发,如果我问的问题太明显,请原谅我。
当我的应用程序的 View 加载时,它会检查某些键的配置,如果这些键没有值,应用程序应显示警报并退出。
首先,我已经实现了 UIAlertViewDelegate:
@interface FirstViewController : UIViewController <UIAlertViewDelegate> {
...
然后检查设置:
- (void)viewDidLoad {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *url = [defaults stringForKey:@"url"];
NSString *apiKey = [defaults stringForKey:@"api-key"];
if([url length] < 1 || [apiKey length] < 1){
UIAlertView *dialog = [[[UIAlertView alloc]
initWithTitle:@"Not properly configured"
message:@"This application was not properly configured. Please configure the application on your iPhone settings."
delegate:self
cancelButtonTitle:@"Close"
otherButtonTitles:nil]
autorelease];
[dialog setTag:1];
[dialog show];
}
[url release];
[apiKey release];
[super viewDidLoad];
}
我知道 alertView didDismissWithButtomIndex 方法应该在 alertView 关闭后调用,但由于某种原因,我的代码中从未调用过此方法。
- (void)alertView:(UIAlertView *)alertView didDismissWithButtomIndex:(NSInteger)buttomIndex {
if([alertView tag] == 1){
exit(0);
}
}
关于为什么会发生这种情况的任何想法?
最佳答案
didDismissWithButtonIndex 拼写错误,您偷偷在其中添加了一个“m”而不是“n”。
关于iphone - 单击 alertView 的按钮后,不会调用 alertView didDismissWithButtomIndex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4751492/