Search code examples
iosobjective-cuipopovercontrolleruiactionsheet

Launch a UIPopover on click of a button inside UIActionSheet


On the left swipe of a row in my Table view, I have two UITableViewRowAction buttons (Delete and More). On the click of More button, I am presenting an UIActionSheet with two buttons named Edit NickName and Edit Photo something like this:

enter image description here

Now I am trying to launch a UIPopover on click of Edit NickName. For that I am using the following code:

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
NSString *buttonTitle = [actionSheet buttonTitleAtIndex:buttonIndex];    

    if ([buttonTitle isEqualToString:@"Edit NickName"]) {
        NSLog(@"Edit NickName");
        UIStoryboard *secondStoryBoard = [UIStoryboard storyboardWithName:@"SplitView" bundle:nil];
        EditNickNameViewController *popVC = [secondStoryBoard instantiateViewControllerWithIdentifier:@"EditNickNameViewController"];

        popover = [[UIPopoverController alloc] initWithContentViewController:popVC];
        popover.delegate=self;
        popover.popoverContentSize = CGSizeMake(600, 300);
        [popover presentPopoverFromRect:CGRectMake(20,20, 0, 0) inView:self.view
           permittedArrowDirections:0 animated:YES];



    }
    if ([buttonTitle isEqualToString:@"Edit Image"]) {
        NSLog(@"Edit Image");
    }
}

The above code works very well inside IBAction of any normal UIButton , but it is not showing any popover in this case.

The above lines of code is getting executed at runtime, but nothing is happening.

Can anyone tell me whether it is possible to do something like this or am I doing any mistake here. If it is not possible, please suggest me an alternative to how to launch something like a popover on click of Edit NickName button.

Thanks in advance!


Solution

  • Present your popover on main queue;

    dispatch_async(dispatch_get_main_queue(), ^{
           [popover presentPopoverFromRect:CGRectMake(20,20, 0, 0) inView:self.view
               permittedArrowDirections:0 animated:YES];
        });