単純なデリゲートを試してみましたが、メソッドが起動しません。これが私のコードです:デリゲートをトリガーするプロトコルとボタンを含むビュー:ViewController.h
#import <UIKit/UIKit.h>
@protocol InitStackDelegate <NSObject>
@required
-(void)initstack:(NSInteger)amount;
@end
@interface ViewController : UIViewController{
IBOutlet UITextField *amountTextField;
__unsafe_unretained id<InitStackDelegate> delegate;
}
- (IBAction)init:(id)sender;
@property (nonatomic,assign)id delegate;
@end
ViewController.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize delegate;
- (IBAction)init:(id)sender {
//send the delegate
[delegate initstack:[amountTextField.text intValue]];
}
AppDelegate.h
#import <UIKit/UIKit.h>
#import "ViewController.h"
@interface AppDelegate : UIResponder <UIApplicationDelegate,InitStackDelegate> {
}
@property (strong, nonatomic) UIWindow *window;
@property (strong,nonatomic) ViewController *myView;
@end
AppDelegate.m
#import "AppDelegate.h"
@implementation AppDelegate
@synthesize window;
@synthesize myView;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
// Override point for customization after application launch.
//..... push second controller into navigation stack
myView.delegate = self;
return YES;
}
...
#pragma mark Delegate Method
-(void)initstack:(NSInteger)amount{
NSInteger test;
}
@end
ボタンを押すと、(IBAction) init が表示されますが、デリゲートは何もしません。AppDelegate.m にブレークポイントを設定しましたが、到達しません。何か助けはありますか?
thxマリオ