Xcode PopOver - 跨文件功能使用?

发布于 2024-11-18 09:04:39 字数 1305 浏览 8 评论 0原文

我的项目中有一个 UIPopoverController 。

文件组成

Mainfile.h 主文件.m Mainfile.xib (VIEW)

tableview.h 表格视图.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"); 

}

提前谢谢你们

I have a UIPopoverController in my project.

File composition

Mainfile.h
Mainfile.m
Mainfile.xib (VIEW)

tableview.h
tableview.m
tableview.xib (TABLE VIEW)

i put my method for my PopoverController in my mainfile. My problem is i cannot access my method from mainfile.m to tableview.m when i select a row in a table.

My code

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];
}

in other file

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"); 

}

Thank you in advance guys

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

新雨望断虹 2024-11-25 09:04:39

我想你有一个 ParentViewController 和一个 childViewControllerPopover 用于某些按钮上的弹出窗口,上面有一个“childViewController”!
使用这样的吹气代码,

要关闭您的 childViewControllerPopover,您可以首先在 ChildViewController.h

@protocol ChildViewControllerDelegate
    -(void)closeView;
@end

@interface ChildViewController : UIViewController{
    id<ChildViewControllerDelegate> delegate;
}
@property (nonatomic, assign) id<ChildViewControllerDelegate> delegate;
@end

当选择 yourTable 的一个 cell 时!您应该调用该方法,因此请将其放入 ChildViewController.m

- (void)tableViewUITableView *)tableView didSelectRowAtIndexPathNSIndexPath *)indexPath  {
    [delegate closeView];
}

和您的 ParnetViewController.h

@interface ParnetViewController : UIViewController <ChildViewControllerDelegate>{
    UIPopoverController *childViewControllerPopover;
}

以及 ParnetViewController.m

- (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
}

I suppose you have a ParentViewController and a childViewControllerPopover for popover on some button and a 'childViewController' on it!
For closing your childViewControllerPopover you can use such a blow code

First in ChildViewController.h

@protocol ChildViewControllerDelegate
    -(void)closeView;
@end

@interface ChildViewController : UIViewController{
    id<ChildViewControllerDelegate> delegate;
}
@property (nonatomic, assign) id<ChildViewControllerDelegate> delegate;
@end

When one cell of yourTable selected! you should call that method, so put this in ChildViewController.m

- (void)tableViewUITableView *)tableView didSelectRowAtIndexPathNSIndexPath *)indexPath  {
    [delegate closeView];
}

And in your ParnetViewController.h

@interface ParnetViewController : UIViewController <ChildViewControllerDelegate>{
    UIPopoverController *childViewControllerPopover;
}

And for ParnetViewController.m

- (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
}
淡莣 2024-11-25 09:04:39

看起来您需要使用委托来调用其他方法。 Xcode 没有全局控制器,可以让您在其他类方法不是程序的焦点时调用它们。

It looks like you need to use a delegate to call the other method. Xcode doesn't have a global controller that lets you call other class methods when they aren't the focus of the program.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文