我需要在viewcontroller中调用一个方法,该方法从创建的popupviewcontroller创建一个popupviewcontroller。
对于iPad,我这样创建:
if (!self.flipsidePopoverController) {
FlipsideViewController *controller = [[[FlipsideViewController alloc] initWithNibName:@"FlipsideViewController" bundle:nil] autorelease];
controller.delegate = self;
self.flipsidePopoverController = [[[UIPopoverController alloc] initWithContentViewController:controller] autorelease];
}
if ([self.flipsidePopoverController isPopoverVisible]) {
[self.flipsidePopoverController dismissPopoverAnimated:YES];
}
else
{
/// The important part ///
[self.flipsidePopoverController presentPopoverFromRect:CGRectMake((self.view.frame.size.width-320), 0, (self.view.frame.size.width), 10) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
现在我希望在弹出窗口中调用主视图控制器中的方法。我怎样才能做到这一点?
我的iPhone相当于:
// Creating it //
FlipsideViewController *controller = [[[FlipsideViewController alloc] initWithNibName:@"FlipsideViewController" bundle:nil] autorelease];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
从弹出窗口中调用方法:
if ([self.presentingViewController isKindOfClass:[MainViewController class]])
[(MainViewController*)self.presentingViewController resetClock];
答案 0 :(得分:0)
为显示的视图控制器提供对主视图控制器的引用。例如:
@class MainViewController;
@interface FlipsideViewController : UIViewController
{
}
@property (nonatomic, assign) MainViewController *mainController;
@end
(不要忘记实施中的@synthesize
!)
稍后当您呈现弹出窗口时,只需设置属性:
[controller setMainController:self];
答案 1 :(得分:0)
·H
#import <UIKit/UIKit>
#import AppDelegate.h"
@interface FlipsideViewController : UIViewController
{
}
@property (nonatomic, assign) MainViewController *mainController;
@end
的.m
#import "FlipsideViewController.h"
#import "MainViewController.h"
@interface FlipsideViewController ()
@end
@implementation FlipsideViewController
@synthesize mainController = _mainController;
// methods
@end