Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xcode PopOver-跨文件函数的使用?_Xcode_Uipopovercontroller_Popover - Fatal编程技术网

Xcode PopOver-跨文件函数的使用?

Xcode 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

我的项目中有一个超级控制器

文件组成

Mainfile.h Mainfile.m Mainfile.xib(视图)

tableview.h tableview.m tableview.xib(表视图)

我把PopoverController的方法放在主文件中。我的问题是,当我在表中选择一行时,我无法从mainfile.m访问tableview.m的方法

我的代码

Mainfile.h

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
}