我刚刚从Xcode模板创建了一个新的实用程序应用程序,我遇到了- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller
方法未被调用的问题。当我使用触控板上的三指点按来定义它时,它表示该方法是在MainViewController.m中定义的,当它肯定在Flip协议中时。
MainVC.h
#import "FlipsideViewController.h"
@interface MainViewController : UIViewController <FlipsideViewControllerDelegate, UIPopoverControllerDelegate>
@property (strong, nonatomic) UIPopoverController *flipsidePopoverController;
@property (weak, nonatomic) IBOutlet UIView *backgroundView;
@end
的.m
#import "MainViewController.h"
@interface MainViewController ()
@end
@implementation MainViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
_backgroundView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Background.jpg"]];
_backgroundView.contentMode = UIViewContentModeCenter;
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Flipside View Controller
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller
{
//width
if (controller.widthSegmentedControl.selectedSegmentIndex == 0) {
//number of icons
} else {
//icon space
}
NSLog(@"b"); // not called
[self.flipsidePopoverController dismissPopoverAnimated:YES];
}
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController
{
self.flipsidePopoverController = nil;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"showAlternate"]) {
[[segue destinationViewController] setDelegate:self];
UIPopoverController *popoverController = [(UIStoryboardPopoverSegue *)segue popoverController];
self.flipsidePopoverController = popoverController;
self.flipsidePopoverController.delegate = self;
}
}
- (IBAction)togglePopover:(id)sender
{
if (self.flipsidePopoverController) {
[self.flipsidePopoverController dismissPopoverAnimated:YES];
self.flipsidePopoverController = nil;
} else {
[self performSegueWithIdentifier:@"showAlternate" sender:sender];
}
}
@end
FlipVC.h
#import <UIKit/UIKit.h>
@class FlipsideViewController;
@protocol FlipsideViewControllerDelegate
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller;
@end
@interface FlipsideViewController : UIViewController
@property (weak, nonatomic) IBOutlet UISegmentedControl *widthSegmentedControl;
@property (weak, nonatomic) IBOutlet UITextField *widthNumberOfIcons;
@property (weak, nonatomic) IBOutlet UITextField *widthIconSpace;
@property (weak, nonatomic) IBOutlet UISegmentedControl *heightSegmentedControl;
@property (weak, nonatomic) IBOutlet UITextField *heightNumberOfIcons;
@property (weak, nonatomic) IBOutlet UITextField *heightIconSpace;
@property (weak, nonatomic) id <FlipsideViewControllerDelegate> delegate;
- (IBAction)done:(id)sender;
@end
的.m
#import "FlipsideViewController.h"
@interface FlipsideViewController ()
@end
@implementation FlipsideViewController
- (void)awakeFromNib
{
self.preferredContentSize = CGSizeMake(320.0, 480.0);
[super awakeFromNib];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Actions
- (IBAction)done:(id)sender
{
NSLog(@"a"); //this is called
[self.delegate flipsideViewControllerDidFinish:self];
}
@end
其中有两个NSLog,一个用于按下完成按钮的方法(a),另一个用于应该调用didFinish方法的方法(b)。问题是当我按下翻转控制器上的完成按钮时没有任何反应(尽管“a”被记录)。
答案 0 :(得分:0)
我发现了问题。我删除了默认的按钮栏信息项,并用普通按钮替换它。问题是segue需要锚定到该按钮并连接到MainViewController.m文件中的togglePopover方法。