Ios Xcode在精细代码中显示错误
我在xcode中声明了一个常量文件Ios Xcode在精细代码中显示错误,ios,iphone,ios7,xcode5,Ios,Iphone,Ios7,Xcode5,我在xcode中声明了一个常量文件 #define MyAppDelegate ((AppDelegate *)[[UIApplication sharedApplication] delegate]) 然后在需要时使用MyAppDelegate。 现在我得到一个错误,MyAppDelegate没有声明,但当我运行这个应用时。它运行得很好,也向我展示了它的错误 #import "SearchResultViewController.h" #import "UIImageView+AFNetwo
#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
;//
}您需要导入头文件
#import "AppDelegate.h"
只需将其创建为一个实例变量,如
YourAppDelegate *appDelegate = (YourAppDelegate *)[[UIApplication sharedApplication] delegate];
tempArray=[appDelegate.searchResultArray mutableCopy];
别忘了导入appdelegate.h
#import "YourAppDelegate.h"
好的,在哪里导入宏引用的
AppDelegate
?im my Constant.h文件。。。。但是它工作得很好,我在文件中添加了一个功能,然后突然出现了这个错误……但是如果我运行时出现了这个错误,它工作得很好。您在哪里导入Constant.h
?我在这个列表中没有看到它。它可以找到,因为类AppDelegate
存在于您的程序中,但是编译器正在抱怨,因为它看不到您列出的代码中的定义。那么我应该在这里做什么呢?