2011-06-25 36 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

相关问题