错误:使用未声明的标识符' alertView'?

时间:2014-12-04 13:43:50

标签: objective-c theos

我正在尝试使用Theos&无法弄清楚什么是错的。编译时我收到此错误: RootViewController.mm:16:13:错误:使用未声明的标识符'alertView'

  • (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSI ......

这是我的代码:

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

1 个答案:

答案 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