Xcode PopOver - использование функции кросс-файла? - PullRequest
0 голосов
/ 05 июля 2011

У меня в проекте есть UIPopoverController.

Состав файла

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

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

Я поместил свой метод для моего 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"); 

}

Заранее спасибо, ребята

Ответы [ 2 ]

2 голосов
/ 26 июня 2012

Полагаю, у вас есть ParentViewController и childViewControllerPopover для всплывающих окон на какой-то кнопке и childViewController на ней! Для закрытия childViewControllerPopover вы можете использовать такой код удара

Первый в ChildViewController.h

@protocol ChildViewControllerDelegate
    -(void)closeView;
@end

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

Когда выбран один cell из yourTable! Вы должны вызвать этот метод, поэтому поместите его в 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
}
0 голосов
/ 06 июня 2012

Похоже, вам нужно использовать делегата для вызова другого метода. Xcode не имеет глобального контроллера, который позволяет вам вызывать другие методы класса, когда они не находятся в центре внимания программы.

...