我可以对自定义代表使用一些帮助。我正在尝试制定一个协议,向其代表发送消息以关闭弹出视图。这是我正在尝试的。
在 popoverViewController.h
#import <UIKit/UIKit.h>
@protocol MyPopoverDelegate <NSObject>
-(void) didSelectLanguage;
@end
@interface Popover : UITableViewController{
id <MyPopoverDelegate> delegate;
NSMutableArray *languageData;
}
@property (nonatomic, assign) id <MyPopoverDelegate> delegate;
@end
.m
@synthesize delegate;
...
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"You selected %@", [languageData objectAtIndex:[indexPath row]]);
[self.delegate didSelectLanguage];
}
...
在呈现弹出框的 ViewController 中
#import <UIKit/UIKit.h>
#import "popoverViewController.h"
@interface ChoicesChoices : UIViewController <UIPopoverControllerDelegate, MyPopoverDelegate>{
UIPopoverController *popover;
}
- (IBAction)facebook:(id)sender;
- (IBAction)twitter:(id)sender;
- (IBAction)sms:(id)sender;
- (IBAction)copy:(id)sender;
- (IBAction)email:(id)sender;
- (IBAction)home:(id)sender;
- (IBAction)mute:(id)sender;
- (IBAction)note:(id)sender;
@property (nonatomic, retain) UIPopoverController* popover;
@end
和.m
@synthesize popover;
...
- (void)didSelectLanguage{
[popover dismissPopoverAnimated:YES];
NSLog(@"didSelectLanguage fired");
}
当我在弹出框的表中选择一行时,不会调用 didSelectLanguage。关于我可能做错了什么的任何想法?谢谢你的帮助。