0

プロジェクトに UIPopoverController があります。

ファイル構成

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

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

}

よろしくお願いします

4

2 に答える 2

2

ParentViewControllerいくつかのボタンにとchildViewControllerPopoverfor のポップオーバーがあり、その上に 'childViewController' があると思います! あなたを閉じるために、childViewControllerPopoverあなたはそのようなブローコードを使うことができます

最初にChildViewController.h

@protocol ChildViewControllerDelegate
    -(void)closeView;
@end

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

いずれかcellyourTable選択すると!そのメソッドを呼び出す必要があるので、これを入れます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
}
于 2012-06-26T11:14:15.803 に答える
0

デリゲートを使用して他のメソッドを呼び出す必要があるようです。Xcode には、他のクラス メソッドがプログラムの対象ではない場合にそれらを呼び出すことができるグローバル コントローラーがありません。

于 2012-06-06T13:04:20.163 に答える