我正在尝试使用Theos&无法弄清楚什么是错的。编译时我收到此错误: RootViewController.mm:16:13:错误:使用未声明的标识符'alertView'
这是我的代码:
RootViewController.h
@interface RootViewController: UIViewController<UIAlertViewDelegate> {
}
@end
RootViewController.mm
#import "RootViewController.h"
@implementation RootViewController
- (void)loadView {
self.view = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease];
self.view.backgroundColor = [UIColor blackColor];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Respring Confirmation"
message:@"Are you sure?"
delegate:self
cancelButtonTitle:@"NO"
otherButtonTitles:@"YES", nil];
[alert show];
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger) buttonIndex
{
if (buttonIndex == [alertView cancelButtonIndex])
{
//NO clicked ...do action
}else{
//YES clicked ...respring code here
}
}
}
@end
答案 0 :(得分:2)
您在[alert show];
之后错过了一个结束括号,最后在@end
之前有一个额外的括号。这应该是它的样子:
#import "RootViewController.h"
@implementation RootViewController
- (void)loadView {
self.view = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease];
self.view.backgroundColor = [UIColor blackColor];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Respring Confirmation"
message:@"Are you sure?"
delegate:self
cancelButtonTitle:@"NO"
otherButtonTitles:@"YES", nil];
[alert show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger) buttonIndex {
if (buttonIndex == [alertView cancelButtonIndex]) {
//NO clicked ...do action
} else {
//YES clicked ...respring code here
}
}
@end