2011-06-25 39 views
0

我試圖將應用程序委託人連接到Xcode4中的視圖控制器,但由於某種原因我無法建立連接,因爲App Delegate無法在可視對象編輯器中看到它。應用程序委託人看不到視圖控制器

在視覺對象編輯器中添加了視圖控制器,並將類ID更改爲HelloWorldViewController,並在App Delegate.h和.m文件中添加了代碼。

我在做什麼錯?

下面是代碼:

testWindowBasedAppDelegate.h

// -- Add a forward reference to the HelloWorldViewController class -- 
@class HelloWorldViewController; 

#import <UIKit/UIKit.h> 

@interface testWindowBasedAppAppDelegate : NSObject <UIApplicationDelegate> { 
    UIWindow *window; 
    //-- create an instance of the view controller -- 
    HelloWorldViewController *viewController; 
} 

@property (nonatomic, retain) IBOutlet UIWindow *window; 

// -- expose the view controller as a property -- 
@property (nonatomic, retain) HelloWorldViewController *viewController; 

@end 

testWindowBasedAppDelegate.m

#import "testWindowBasedAppAppDelegate.h" 
#import "HelloWorldViewController.h" 

@implementation testWindowBasedAppAppDelegate 


@synthesize window; 
//-- synthesize the property-- 
@synthesize viewController; 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    // Override point for customization after application launch. 
    //-- add the new view to the current window -- 
    [window addSubview:viewController.view]; 
    [self.window makeKeyAndVisible]; 
    return YES; 
} 

- (void)dealloc 
{ 
    [viewController release]; 
    [window release]; 
    [super dealloc]; 
} 

@end 
+0

到底是什麼問題嗎?你想做什麼?嘗試附上代碼,我可以看看它 – Sum

回答

1

您需要添加一個IBOutlet標記爲IB看到它。申報財產的,

@property (nonatomic, retain) IBOutlet HelloWorldViewController *viewController; 

這甚至也適用於那些要公開,但在那裏你會使用IBAction代替方法。例如,

- (IBAction)doSomething; 

這兩個標籤都只是指標和實際聲明,

#define IBAction void 
#define IBOutlet 
+0

這工作!謝謝! – pdenlinger

相關問題