我在xcode中声明了一个我声明了
的常量文件#define MyAppDelegate ((AppDelegate *)[[UIApplication sharedApplication] delegate])
然后在需要时使用MyAppDelegate。 现在我收到的错误是MyAppDelegate未被声明,但是当我运行这个应用程序时。它运行正常,并向我显示错误。
#import "SearchResultViewController.h"
#import "UIImageView+AFNetworking.h"
#import "SearchResultCell.h"
@interface SearchResultViewController ()
@end
@implementation SearchResultViewController
@synthesize tempArray;
- (id)initWithStyle:(UITableViewStyle)style {
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
UIBarButtonItem *btnHelp = [[UIBarButtonItem alloc] initWithTitle:@"Help" style:UIBarButtonItemStylePlain target:self action:@selector(btnHelpAction:)];
self.navigationItem.rightBarButtonItem=btnHelp;
self.title = @"Search Result";
tempArray=[[NSMutableArray alloc]init];
tempArray=[MyAppDelegate.searchResultArray mutableCopy]; // showing me error
;//
}
答案 0 :(得分:0)
您需要导入头文件。
#import "AppDelegate.h"
答案 1 :(得分:0)
只需将其创建为
之类的实例变量即可YourAppDelegate *appDelegate = (YourAppDelegate *)[[UIApplication sharedApplication] delegate];
tempArray=[appDelegate.searchResultArray mutableCopy];
别忘了导入 YourAppDelegate.h
#import "YourAppDelegate.h"