我想使用委托将信息从玩家视图控制器发送到当前匹配视图控制器。唯一的事情是PlayersViewCotroller和GameDetailsViewController被另一个视图控制器分开。我该怎么做才能确保调用选择器?我错过了什么吗?
#import <UIKit/UIKit.h>
@class PlayersViewController;
@protocol PlayersViewControllerDelegate <NSObject>
- (void)addItemViewController:(PlayersViewController *)controller didFinishEnteringPlayer1:(NSString *)player1 didFinishEnteringPlayer2:(NSString *)player2;
@end
@interface PlayersViewController : UIViewController
@property (weak, nonatomic) IBOutlet UITextField *player1;
@property (weak, nonatomic) IBOutlet UITextField *notes1;
@property (weak, nonatomic) IBOutlet UITextField *player2;
@property (weak, nonatomic) IBOutlet UITextField *notes2;
@property (weak, nonatomic) IBOutlet UIBarButtonItem *nextButton;
- (IBAction)nextButtonPressed:(id)sender;
@property (nonatomic, weak) id <PlayersViewControllerDelegate> pdelegate;
@end
PlayersViewController.m
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqual:@"playersSegue"]) {
if([self.pdelegate respondsToSelector:@selector(addItemViewController:didFinishEnteringPlayer1:didFinishEnteringPlayer2:)]){
[self.pdelegate addItemViewController:self didFinishEnteringPlayer1: player1.text didFinishEnteringPlayer2: player2.text];
NSLog(@"Works");
}
}
CurrentMatchViewController.m(将信息发送到此视图控制器)
- (void)addItemViewController:(PlayersViewController *)controller didFinishEnteringPlayer1:(NSString *)player1 didFinishEnteringPlayer2:(NSString *)player2 {
NSLog(@"%@", player1);
}