我是 iOS 编程的新手,我无法让这个简单的概念起作用——我只希望弹出控制器能够调用方法并在父控制器上发送数据。谁能发现我在这里做错了什么?
在 DetailViewController.h
#import <UIKit/UIKit.h>
#import "Employee.h"
#import "CompleteViewController.h"
@class EmployeesTVC;
@interface DetailViewController : UIViewController <UISplitViewControllerDelegate, UIPopoverControllerDelegate>
@property (strong) UIPopoverController *popController;
-(IBAction)completeButtonPressed:(id)sender;
@end
在 DetailViewController.m 中(取出不相关的部分)
@implementation DetailViewController {
__weak UIPopoverController *completePopover;
}
// ...
#pragma mark - Complete / Score popover methods
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
NSLog(@"preparing for segue");
UIStoryboardPopoverSegue *popoverSegue = (UIStoryboardPopoverSegue *)segue;
UIPopoverController *scorePopoverController = [popoverSegue popoverController];
[scorePopoverController setDelegate:self];
self.popController = scorePopoverController;
}
- (IBAction)completeButtonPressed:(id)sender {
if (completePopover) {
[completePopover dismissPopoverAnimated:YES];
} else {
[self performSegueWithIdentifier:@"showScorePopover" sender:sender];
}
}
- (void) scoreAssigned:(NSString *)score {
NSLog(score);
NSLog(@"Score Assigned");
}
// ...
@end
CompleteViewController.h(弹出视图控制器)
#import <UIKit/UIKit.h>
@protocol CompleteViewDelegate <NSObject>
- (void)scoreAssigned:(NSString *)score;
@end
@interface CompleteViewController : UIViewController
@property (nonatomic, assign) id<CompleteViewDelegate> delegate;
- (IBAction)okButtonPressed:(id)sender;
@end
CompleteViewController.m
#import "CompleteViewController.h"
@implementation CompleteViewController
@synthesize delegate;
- (IBAction)okButtonPressed:(id)sender {
NSLog(@"OK Button Pressed");
[delegate scoreAssigned:@"100"];
}
@end