Xcode PopOver-跨文件函数的使用?
我的项目中有一个超级控制器 文件组成 Mainfile.h Mainfile.m Mainfile.xib(视图) tableview.h tableview.m tableview.xib(表视图) 我把PopoverController的方法放在主文件中。我的问题是,当我在表中选择一行时,我无法从mainfile.m访问tableview.m的方法 我的代码 Mainfile.hXcode PopOver-跨文件函数的使用?,xcode,uipopovercontroller,popover,Xcode,Uipopovercontroller,Popover,我的项目中有一个超级控制器 文件组成 Mainfile.h Mainfile.m Mainfile.xib(视图) tableview.h tableview.m tableview.xib(表视图) 我把PopoverController的方法放在主文件中。我的问题是,当我在表中选择一行时,我无法从mainfile.m访问tableview.m的方法 我的代码 Mainfile.h UIPopoverController *popMenu; @property(nonatomic,retain
UIPopoverController *popMenu;
@property(nonatomic,retain) IBOutlet UIPopoverController *popMenu;
-(IBAction)showPopOverid) sender;
-(IBAction)hidePopOver;
Mainfile.m
#import "tableview.h"
-(IBAction)showPopOverid) sender {
if ([popMenu isPopoverVisible]) {
[popMenu dismissPopoverAnimated:YES];
} else {
tableview *toc = [[tocView alloc] init];
popMenu = [[UIPopoverController alloc] initWithContentViewController:toc];
[toc release];
[popMenu presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAn y animated:YES];
}
}
-(IBAction)hidePopOver {
NSLog(@"hidePopOver");
[popMenu dismissPopoverAnimated:YES];
}
在其他文件中
tableview.m
- (void)tableViewUITableView *)tableView didSelectRowAtIndexPathNSIndexPath *)indexPath {
//I WANT TO ACCESS THE METHOD of hidePopOver from the mainfile so i can hide my popViewController
// i've tried a lot but not working
NSLog(@"hidePopOver");
}
提前感谢各位看起来您需要使用一个委托来调用另一个方法。Xcode没有全局控制器,当其他类方法不是程序的焦点时,您可以调用它们。我想您在某些按钮上有一个用于popover的
ParentViewController
和一个childViewControllerPopover
,还有一个“childViewController”!
要关闭您的ChildViewControllerPover
,您可以使用这样的代码
ChildViewController.h中的第一个
@protocol ChildViewControllerDelegate
-(void)closeView;
@end
@interface ChildViewController : UIViewController{
id<ChildViewControllerDelegate> delegate;
}
@property (nonatomic, assign) id<ChildViewControllerDelegate> delegate;
@end
在您的ParnetViewController.h
@interface ParnetViewController : UIViewController <ChildViewControllerDelegate>{
UIPopoverController *childViewControllerPopover;
}
@interface ParnetViewController : UIViewController <ChildViewControllerDelegate>{
UIPopoverController *childViewControllerPopover;
}
- (void)viewDidLoad
{
[super viewDidLoad];
ChildViewController *childViewController = [[ChildViewController alloc] init];
childViewController.delegate = self;
childViewControllerPopover = [[UIPopoverController alloc] initWithContentViewController:childViewController];
[childViewController release];
}
-(void)closeView{
[childViewControllerPopover dismissPopoverAnimated:YES];
// Do anything
}