如何手动关闭UAModalPanel

时间:2012-09-05 08:09:30

标签: iphone xcode uiviewcontroller modalviewcontroller

我已经下载了一个很好的示例代码UAModalPanel。我已经在我的项目中实现了它,如果我们点击段控件的第一个索引它将打开UAModalPanel。我可以成功地实现这个。

但是如果我们在分段控制中选择第二个或第三个索引,我需要关闭UAModalPanel我怎样才能实现这个目标。如果有人知道指导我?

enter image description here 如果我们点击以下段控件将被称为

   -(void)navBarSegmentCntrl_tapped
{
if(navBarSegmentCntrl.selectedSegmentIndex==0)
{

    UAExampleModalPanel *modalPanel = [[UAExampleModalPanel alloc] initWithFrame:self.view.bounds title:@"dfg" ];



    [self.view addSubview:modalPanel];

    // Show the panel from the center of the screen
    [modalPanel showFromPoint:self.view.center];



}
else if(navBarSegmentCntrl.selectedSegmentIndex==1)
{
    [UAmodal hide];  //UAmodal allocated in view didload//
    imagePickerController = [[UIImagePickerController alloc] init];
    imagePickerController.delegate = self;
    imagePickerController.sourceType = 
    UIImagePickerControllerSourceTypePhotoLibrary;

    [self presentModalViewController:imagePickerController animated:YES];   
}

}

1 个答案:

答案 0 :(得分:1)

问题是您呼叫的对象show与您呼叫的hide不同。您应该在接口文件中声明它:

@interface MyViewController : UIViewController
{
    UAModalPanel *myModalPanel;
}

然后,当您使用navBarSegmentCntrl_tapped方法显示它时,您会初始化myModalPanel(请记住,一旦您已经设置了它,就不需要再次UAModalPanel *myModalPanel,并且您的视图控制器“已经知道该对象”。您只需myModalPanel = [[UAModalPanel alloc] init....)。

然后,要隐藏它,只需拨打[myModalPanel hide];