从子视图调用superview中的方法

时间:2011-01-24 03:34:06

标签: cocoa-touch uiview

我已经浏览了网站以寻找答案,但似乎没有任何帮助我

这是我的情景 我有一个名为settingsView的主视图。 使用以下

从settingsView调用子视图AboutView
        aboutView = [[AboutView alloc] initWithNibName:@"AboutView" bundle:nil];
        CGRect theFrame = aboutView.view.frame;
        theFrame.origin = CGPointMake(330,50);
        aboutView.view.frame = theFrame;
        theFrame.origin = CGPointMake(0,50);
        theFrame.size.width=320;
        theFrame.size.height=360;       
        [UIView beginAnimations:nil context:nil]; 
        [UIView setAnimationDuration:0.5f];
        aboutView.view.frame = theFrame;
        [UIView commitAnimations];
        [self.view addSubview:aboutView.view];  

我想调用一个方法,甚至在settingsView中调用viewDidAppear方法,一旦aboutView被解除。

我已经尝试了几乎所有我在这个论坛中找到的方式

在aboutView中,我试过了 [self.view.superview viewDidAppear]; [self.parentViewControllers ...] //返回null,因为我没有使用presentViewController

我已阅读有关设置委托的建议,但无论出于何种原因,我都无法为aboutView设置委托。

有什么建议吗?

1 个答案:

答案 0 :(得分:1)

- (void)viewController {
    for (UIView* next = [self.view superview]; next; next = next.superview) {
        UIResponder* nextResponder = [next nextResponder];
        if ([nextResponder isKindOfClass:[UIViewController class]]) {
            [(UIViewController*)nextResponder viewWillAppear:YES];
        }
    }
}

我使用了Three20库中的上述代码。在子视图中定义了一个方法并调用它。它有效,但这是正确的方法吗?还有其他更简单的方法吗?

由于