Ios 简单委托方法不起作用

Ios 简单委托方法不起作用,ios,delegates,ios4,Ios,Delegates,Ios4,我们将非常感谢您的帮助 我有一个简单的项目用于测试: 我想在委托方法中传递NSString,但使用此代码不起作用 testDelegateViewController.h @protocol testDelegateViewControllerDelegate; @interface testDelegateViewController : UIViewController { id<testDelegateViewControllerDelegate> delegate

我们将非常感谢您的帮助

我有一个简单的项目用于测试:

我想在委托方法中传递NSString,但使用此代码不起作用

testDelegateViewController.h

@protocol testDelegateViewControllerDelegate; 


@interface testDelegateViewController : UIViewController {


id<testDelegateViewControllerDelegate> delegate;

IBOutlet UIButton *button;

}

@property (nonatomic, assign) id<testDelegateViewControllerDelegate> delegate;
@property (nonatomic, retain) IBOutlet UIButton *button;

- (void)pass;

@end

@protocol testDelegateViewControllerDelegate

- (void)passSomeToDelegate:(NSString *)some;

@end
AppDelegate.h

#import "testDelegateViewController.h"

@interface AppDelegate : NSObject <UIApplicationDelegate, testDelegateViewControllerDelegate> {

}
但在我的控制台中,当按下按钮时,不会打印任何内容


谢谢你忘了设置你的代表。您可以在
应用程序:didFinishLaunchingWithOptions:
方法中设置委托

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{   
    self.viewController.delegate = self;

    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}

我添加了
self.viewController.delegate=self
设置委托。

您忘记设置委托。您可以在
应用程序:didFinishLaunchingWithOptions:
方法中设置委托

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{   
    self.viewController.delegate = self;

    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}

我添加了
self.viewController.delegate=self
设置代理。

这对像我这样的初学者很有帮助。这对像我这样的初学者很有帮助。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{   
    self.viewController.delegate = self;

    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}