我试图在弹出窗口中单击按钮时关闭弹出窗口并返回变量。有四个按钮,在选择一个按钮时,变量(基于按钮)将返回到原始视图控制器并且弹出框将关闭。我不确定如何尝试传递变量,但我正在尝试使用此页面(http://stackoverflow.com/questions/3565968/dismiss-popover-using-uibutton)至少在按钮单击时关闭弹出框),由于某种原因,这对我不起作用。当我单击按钮时,绝对没有任何反应。
AddWineViewController 是“根”视图控制器
//AddWineViewController.h
//this is the "root" view controller
#import "WineStyleViewController.h"
@interface AddWineViewController : UIViewController <UIPopoverControllerDelegate, MyPopoverDelegate>
@property (nonatomic, retain) UIPopoverController *myPopoverController;
//AddWineViewController.m
@implementation AddWineViewController
@synthesize myPopoverController;
-(void)didClickCancelButton {
//I would like to have the variable passed here, something like self.wineStyle.text=wineStyle; where wineStyle is the variable from the popover.
[myPopoverController dismissPopoverAnimated:YES];
}
WineStyleViewController 是弹出视图控制器
//WineStyleViewController.h
@protocol MyPopoverDelegate <NSObject>
-(void)didClickCancelButton;
@end
@interface WineStyleViewController : UIViewController
@property (nonatomic, assign) id<MyPopoverDelegate> delegate;
@property (nonatomic, strong) NSString *wineStyle;
- (IBAction)redWineButton:(id)sender;
//WineStyleViewController.m
@implementation WineStyleViewController
@synthesize wineStyle;
@synthesize delegate;
- (IBAction)redWineButton:(id)sender {
wineStyle=@"Red";
[self.delegate didClickCancelButton];
}