AntonBoer AntonBoer - 1 year ago 111
Objective-C Question

Translucent UITableView on a UIPopoverView

I am unable to make my

on a
translucent, Apple style. Here's the code I am using with comments on what I have already tried and found not working. Any help much appreciated!

Please note that I cannot use Storyboard segues as I am launching this popover from a dynamic tableview cell cell prototype.

popoverViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"TargetPickVC"]; = _target;
//popoverViewController.tableView.backgroundColor = [UIColor clearColor]; // Does nothing
//popoverViewController.tableView.alpha = 0.1; // Does make tableview text lighter

UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:popoverViewController];
nav.modalPresentationStyle = UIModalPresentationPopover;

UIPopoverPresentationController *popPC = nav.popoverPresentationController;

//popPC.containerView.alpha = 0.1; // Does nothing

nav.popoverPresentationController.sourceRect = ((UITableView*)[self.tableView cellForRowAtIndexPath:indexPath]).frame;
nav.popoverPresentationController.sourceView = self.view;
popPC.permittedArrowDirections = UIPopoverArrowDirectionAny;
popPC.delegate = self;

//popoverViewController.tableView.backgroundColor = [UIColor clearColor]; // No
//popoverViewController.view.backgroundColor = [UIColor clearColor]; // visible
//nav.view.backgroundColor = [UIColor clearColor]; // results

dispatch_async(dispatch_get_main_queue(), ^{
[self presentViewController:nav animated:YES completion:nil];

Current result looks like this:
Opague popover

Answer Source

First of all you actually can use segues with dynamic prototypes - just click on your prototype when pushing ctrl and then drag to your target scene. You can preconfigure that VC in -prepareForSegue: method

If you are doing this on iPad then add this line nav.popoverPresentationController.backgroundColor = [UIColor clearColor]; It should help to remove white background from your popover. But it won't help on iPhone - you will see a black background, which is main window's background. To fix it you will need to change UIModalPresentationPopover to UIModalPresentationOverCurrentContext specifically for iPhone.

But if it won't help and you will continue getting a white background - try to set background color to all layers of your view hierarchy - your navigation controller, TargetPickVC and tour table view. Like this

popoverViewController.tableView.backgroundColor = [UIColor clearColor];
popoverViewController.view.backgroundColor = [UIColor clearColor]; 
nav.view.backgroundColor = [UIColor clearColor];

Hopefully it will help