2012-11-28 99 views
0

我有一個根視圖控制器,其中我加載了一個包含三個按鈕的子視圖。當我觸摸其中的一個時,會顯示彈出窗口。彈出窗口包含一個圖像視圖和一個帶有完成按鈕的欄。我想在完成按鈕被觸摸時關閉此彈出窗口。要做到這一點,我使用這個代碼關閉彈窗視圖

- (IBAction)btnDone:(UIBarButtonItem *)sender { 
    [self.view removeFromSuperview]; 

     [APPDELEGATE.parkDetail. popoverController dismissPopoverAnimated:YES]; 
    // [APPDELEGATE.parkDetail.popoverController dismissPopoverAnimated:YES ]; 


} 

和酥料餅提出這樣

- (IBAction)btnParkMap:(id)sender { 
     [popoverController dismissPopoverAnimated:YES]; 
    if ([popoverController isPopoverVisible]) { 
     [popoverController dismissPopoverAnimated:YES]; 
    } else { 
     parkMap * v = [[parkMap alloc]initWithNibName:@"parkMap" bundle:nil]; 
     v.contentSizeForViewInPopover = CGSizeMake(350, 300); 
     popoverController = [[UIPopoverController alloc] initWithContentViewController:v]; 
       CGRect popRect = CGRectMake(self.btnShowPopover.frame.origin.x+330, 
            self.btnShowPopover.frame.origin.y+170, 
            self.btnShowPopover.frame.size.width, 
            self.btnShowPopover.frame.size.height); 


     [popoverController presentPopoverFromRect:popRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES]; 
      } 
} 
+0

你已經完成parkMap類的按鈕了嗎? –

回答

1

嘗試寫下面的代碼

[yourPopOverobject dismissPopoverAnimated:YES]; 

讓我知道,無論是工作或沒有..

快樂編碼!!!!!

+0

我試過這個,但它不工作 –

+0

沒有它不工作 –

+0

它應該工作的人...告訴我你是如何提供彈出控制器..寫一些代碼... – NiravPatel

3

試試這個代碼

[self dismissViewControllerAnimated:YES completion:nil]; 

或者試試@ nirav的ANS

+0

我編輯問題先生 –

+0

它工作爲了你? – Shyantanu

0
- (IBAction)btnDone:(UIBarButtonItem *)sender { 

     [self dismissViewControllerAnimated:YES completion:nil]; 


    } 
0

嘗試查看下面的代碼...

if ([popoverobject isPopoverVisible]) { 
    [popoverobject dismissPopoverAnimated:YES]; 
    [popoverobject release]; 
} 

}

#pragma mark - 
#pragma mark UIPopoverController delegate 

-(void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController { 
//if (popoverController == popoverobject) { 
    [popoverobject release]; 
// } 
} 

- (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController { 

    NSLog(@\"popover about to be dismissed\"); 
    return YES; 
    } 

讓我知道它是否正在工作...

+0

Nirav Patel我可以把這個代碼 –

+0

放在你想關閉彈出控制器的同一類中 – NiravPatel

+0

不工作sir –

1

PopUpOver可以關閉UIWebView的默認上下文菜單。這很簡單,因爲我們只需要爲網頁的body元素設置CSS屬性「-webkit-touch-callout」爲「none」。我們可以在UIWebView委託方法「webViewDidFinishLoad:」中使用JavaScript來做到這一點... ...

- (void)webViewDidFinishLoad:(UIWebView *)webView 
{ 
[webView stringByEvaluatingJavaScriptFromString:@"document.body.style.webkitTouchCallout='none';"]; 
}