2013-01-14 36 views
0

訪問到的UIScrollView我有兩個的viewController: AController(UIScrollView的是子視圖)和BController從其他的viewController

  • 從AController我使用presentModalViewController到BController。從BController我使用dismissModalViewControllerAnimated回到AController。但是,我想從BController隱藏UIScrollView。

請幫幫我! 謝謝!

回答

0

使用委託,如果你沒有在你的AView viewWillAppear中通知了這麼多expariance使用:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(hideScrollView) name:@"hideScrollView" object:nil]; 

,並在您BView使用:

[[NSNotificationCenter defaultCenter] 
    postNotificationName:@"hideScrollView" object:nil]; 

在結果,我將會觸發hideScrollView方法AView當你可以隱藏你的scrollView。

+0

不錯!謝謝... –

0

我認爲最簡單的方法是使用委託協議。 AController將成爲BController的代表。並且在BController被解僱之前,它可以調用協議的一個方法來提醒AController,而AController本身同時隱藏scrollView。

或者,您可以在AController實現文件中覆蓋-viewWillAppear,以測試'self.presentedController'是否是BController的子類。如果是,你可以隱藏scrollView。

- (void)viewWillAppear:(BOOL)animated 
{ 
    [super viewWillAppear:animated]; 

    if ([self.presentedViewController isKindOfClass:[BController class]]) { 
     //hide the scroll view 
    } 
} 

另外,我建議你,除非你想支持的iOS 4和更早的版本不使用-dismissModalViewControllerAnimated::此方法已在iOS 6中棄用,你最好使用- dismissViewControllerAnimated:completion:的時候了。

+0

哦,非常感謝 –

相關問題