2011-05-10 42 views
1

我有一個奇怪的艾利我issue.Let第一代碼發佈到您不能訪問我的應用程序代理的屬性和方法在另一個類的iOS 4.3

在我appdelegate.h

#import <UIKit/UIKit.h> 
#import <CoreData/CoreData.h> 
#import "SecondViewController.h" 

@class MasterViewController; 
@class DetailViewController1; 


@interface TestAppDelegate : NSObject <UIApplicationDelegate> { 


    NSTimer *tempTimer; 

} 


@property(nonatomic, retain) NSTimer *tempTimer; 


-(void)test; 


@end 


In my app delegate .m 

@synthesize tempTimer 

在我SecondViewController.h

@class TestAppDelegate; 

@interface SecondViewController : UIViewController 
{ 


    TestAppDelegate *appDel; 
    NSTimer *aTimer; 

} 


@property (nonatomic, retain) NSTimer *aTimer; 


@end 

在我SecondViewCo ntroller.m

@synthesize aTimer, appDel; 

viewDidload方法

appDel =(TestAppDelegate *)[[UIApplication sharedApplication] delegate]; 
self.aTimer = appDel.tempTimer; 

現在我得到以下錯誤

*屬性 「tempTimer」 不是類型的對象中找到 「TestAppDelegate

+0

「testTimer」是錯誤中的拼寫錯誤嗎?它似乎是「tempTimer」。 – Bemmu 2011-05-10 10:54:46

+0

對不起,我的錯誤,看看我編輯了這個問題。它tempTimer無處不在 – Swastik 2011-05-10 10:57:51

回答

1

原因是,你已經在SecondViewController中聲明瞭TestAppDelegate,因此不能訪問屬性。我認爲你這樣做的原因是爲了避免這些類之間的循環依賴。您有兩種選擇:

  • 在SecondViewController.m中導入TestAppDelegate.h。
  • 刪除循環依賴項並在SecondViewController.h中導入TestAppDelegate而不是@class TestAppDelegate;
+0

@UdayKumar謝謝!我想這可能是因爲循環依賴,但我不確定它。 – Swastik 2011-05-11 04:18:16

1

只需添加#進口「appdelegate.h」到SecondViewController.m的頂部,你不需要將它添加到頭文件作爲這樣做的頂部將導致使用SecondViewController也導入的appdelegate所有類.h,但通過在m文件中這樣做,它只能導入與SecondViewController.m有關的方法

相關問題