简体   繁体   中英

Dismiss UIPopOverPresentationcontroller

I have class ViewControllerA from which i present a UIPopoverPresentationcontroller which display's data from class B, Which works fine. When i select a value in pop Over i want to dismiss it. My code is as below

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    NSString *getLang=[self.myArr objectAtIndex:indexPath.row];
    if ([getLang isEqualToString:@"Ragul"]) {
        getLang=@"Received";
    }
    else if ([getLang isEqualToString:@"Gokul"])
    {
    getLang=@"Denied";
    }
    ViewControllerA *viewCont=[[ViewControllerA alloc]init];
    viewCont.delegate=self;
    [self  dismissViewControllerAnimated:YES completion:nil];

    [viewCont anOptionalMethod:getLang];
}

anOptionalMethod is a custom delegate method which i call to show data with the value selected from PopOver.

-(void)anOptionalMethod:(NSString *)langLocal
 { 
    [self viewDidLoad]; 
    self.popController.delegate = self; 
    [self.ContPop dismissViewControllerAnimated:YES completion:nil];
    self.langShown=YES; 
    lblText.Text=MyValue; 
    [self.view addSubview:lblText]; // This calls viewDidLoad method 
} 

When i add the result to the ViewControllerA with [Self.view addSubview:MyValue] the viewDidLoad method is called. So this should not happen. I know that popOverPresentationController acts as parent view and so i'm getting this problem. So please help me to solve this. ThankYou in advance..

To dismiss UIPopoverPresentationcontroller programatically,

  [[vc presentingViewController] dismissViewControllerAnimated:YES completion:NULL];

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM