這個錯誤很奇怪。我有一堆應用程序委託中的屬性,我沒有問題訪問。我的代碼工作正常,沒有ARC,但是當我打開ARC時,我收到了這個非常奇怪的錯誤。 在'AppDelegate *'類型的對象上未找到屬性'navigationController'屬性'x'沒有在類型'y *'的對象上找到只有ARC的錯誤
除此之外,其他一些屬性可以正常工作。
我已經清理了一切並重新啓動了Xcode。
下面是代碼:
AppDelegate.h:
@interface AppDelegate : UIResponder <UINavigationControllerDelegate> {
UINavigationController *navigationController;
NSString *appName;
}
@property (strong, nonatomic) NSString *appName;
@property (strong, nonatomic) UINavigationController *navigationController;
AppDelegate.m
#import "AppDelegate.h"
@synthesize navigationController, appName;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
appName = [NSString stringWithString:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"]];
navigationController = [[UINavigationController alloc] initWithRootViewController:self.startViewController];
}
MyClass.h
@class AppDelegate;
@interface MyClass: UIResponder {
AppDelegate *appDelegate;
}
MyClass.m
#import "AppDelegate.h"
#import "MyClass.h"
@implementation MyClass
- (id)init
{
self = [super init];
if (self) {
// Initialization code here.
appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[self initFacebook];
}
return self;
}
- (void) doStuff {
NSLog(@"App Name:%@",appDelegate.appName); //this works fine
//This one doesn't
UINavigationController *myNavigationController = appDelegate.navigationController;
}
更新: 我做了一個解決方法。基本上我在MyClass中創建了一個名爲navigationViewController的屬性,並且在MyClass在AppDelegate中實例化之後傳遞對象,而不是直接從MyCLass中的AppDelegate獲取(如上所示)。我仍然困惑,它必須是編譯器中的一個錯誤。我仍然對如何使原始代碼工作非常感興趣。
對不起,這是一個錯字,代碼是更長的時間,我只是刪除了一切。它編譯得很好,沒有ARC標誌。我正要提交應用程序,當我運行分析時顯示代碼因爲沒有ARC標誌而泄漏。我刪除了旗幟和砰!我得到了錯誤。它是一個包含10個視圖控制器的複雜應用程序,其他文件編譯得很好。 – Tibidabo