我在 firstViewController 中的 Xcode 中创建了一个新的选项卡式视图项目我创建了一个这样的协议
@protocol myProtocol <NSObject>
-(void)myProtocolMethodOne;
@end
@interface FirstViewController : UIViewController
@property (weak) id<myProtocol> mypDelegate;
- (IBAction)button1Tap:(id)sender;
@end
在 .m 文件中我做了这个
@synthesize mypDelegate;
.
.
.
- (IBAction)button1Tap:(id)sender
{
[mypDelegate myProtocolMethodOne];
}
这是 secondViewController .h 文件
@interface SecondViewController : UIViewController <myProtocol>
@property (strong) FirstViewController *fvc;
@end
这是 .m 文件
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = NSLocalizedString(@"Second", @"Second");
self.tabBarItem.image = [UIImage imageNamed:@"second"];
_fvc = [[FirstViewController alloc]init];
[_fvc setMypDelegate:self];
}
return self;
}
-(void)myProtocolMethodOne
{
NSLog(@"2nd VC");
[[self tabBarItem]setBadgeValue:@"ok"];
}
myProtocolMethodOne 不工作,我做错了什么?