我有一个问题,我想从另一个控制器调用一个视图控制器中定义的函数。我尝试了一百种不同的设置,但似乎没有任何效果。
我已经发布了基本代码,希望有人能告诉我他们会怎么做。基本上,我要做的就是在按下 dealB 按钮时从 GameViewController 调用 SwitchViewController 中定义的 MYBPress 函数。任何帮助将不胜感激。PS:我已经编码了很长时间,但对 Obj-C 来说真的很陌生
// ------- SwitchViewController.h ---------------
#import <UIKit/UIKit.h>
@class GameViewController;
@class OptionsViewController;
@interface SwitchViewController : UIViewController {
OptionsViewController *optionsViewController;
}
@property ( retain, nonatomic ) OptionsViewController *optionsViewController;
@property ( retain, nonatomic ) GameViewController *gameViewController;
-(IBAction)MyBPress:(id)sender;
@end
// -------- GameViewController.h ------------
#import <UIKit/UIKit.h>
@interface GameViewController : UIViewController {
IBOutlet UIButton *dealB;
}
@property(nonatomic,retain) IBOutlet UIButton *dealB;
- (IBAction)dealB:(id)sender;
@end
// ------- GameViewController.m
#import "GameViewController.h"
@implementation GameViewController
@synthesize dealB; // The Deal button
- (IBAction)dealB:(id)sender
{
// Here is where I want to call the MyBPress function
}
@end