2011-07-05 4 views
0

私のプロジェクトにはUIPopoverControllerがあります。Xcode PopOver - クロスファイル機能を使用していますか?

ファイル構成

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

} 

あらかじめありがとう

答えて

0

他のメソッドを呼び出すためにデリゲートを使う必要があるようです。 Xcodeには、プログラムの中心でないときに他のクラスメソッドを呼び出すことができるグローバルコントローラはありません。

2

一部のボタンでpopoverのためにParentViewControllerchildViewControllerPopoverがあり、その上に 'childViewController'があるとします。閉じるための あなたのcell選択するときは、ChildViewController.h

@protocol ChildViewControllerDelegate 
    -(void)closeView; 
@end 

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

に、このようなブローコード

ファーストを使用することができます!あなたは、そのメソッドを呼び出し、その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 
} 
ためで、これを置く必要があります
関連する問題