2013-09-11 41 views
1

我從多個位置調用一個模態視圖控制器,並且當我關閉它時我想知道它在哪個視圖上,所以我可以調用一個更新函數if這是我製作的這個自定義列表。確定調用模態視圖的視圖控制器

我想知道如何在模態視圖下的ViewController中調用方法。

現在我已經建立了一個委託,但它似乎沒有調用我設置的方法。

請參閱代碼。

ViewController.h

@interface PICTSharePictViewController : PICTBaseShareViewController <PICTConnModalViewControllerDelegate> 

.M

-(void)viewDidLoad{ 

      PICTConnModalViewController *cmodal = [self.storyboard instantiateViewControllerWithIdentifier:@"connModal"]; 
    cmodal.pictDelegate = self; 
} 

-(void)checkSwitches:(PICTConnModalViewController*)sender{ 
    NSLog(@"-----Check-----"); 
} 

而ModalView

.H

@class PICTConnModalViewController; 

@protocol PICTConnModalViewControllerDelegate 
-(void)checkSwitches:(PICTConnModalViewController*)sender; 

@end 

@interface PICTConnModalViewController : PICTBaseViewController { 

    __weak id <PICTConnModalViewControllerDelegate> sliderDelegate; 

} 


@property (nonatomic, weak) id <PICTConnModalViewControllerDelegate> pictDelegate; 

.M

-(void)viewDidLoad{ 

    [pictDelegate checkSwitches:self]; 
} 

我沒有得到任何錯誤或任何警告。誰能告訴我我做錯了什麼?

回答

1

您可以通過在模態/呈現的VC上使用-[UIViewController presentingViewController]方法來訪問呈現模態視圖控制器的視圖控制器。

+0

嗯,類似的東西? '[present presentViewController:cmodal animated:YES completion:^ {}];'或者你所暗示的不同? –

+0

該方法是你如何*呈現*模態VC。 ''自展示視圖控制器''是你如何從*呈現的*(模態)VC訪問原始的*呈現* VC。 –

+0

Ahh sweet尼克,我會試試 –