Displaying a popover view from dynamic prototype cells

I am developing an iPad application with a custom split view. In the main view, I have a tableViewController. I add items to this button with the add button on the navigation bar. This button is connected (I work with the storyboard) using a popover segue for another tableViewController that contains several cells for data input. The save button rejects the popover view above the add item in the masterView list. What I want to do next is the prototype link cells of the link wizard for another view to allow the user to edit the selected item. I want to associate this view with a popover segue (as with the add button), and there is a problem there: I get a red error from xcode: Failed to compile the connection: => anchorView = →.

This is a sample of my code that works great. I would like to do the same when I click on a cell for editing.

MasterSplitView table

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"assetCell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    // Configure the cell...
    AssetModel *myAssetModel = [self.arrayAsset objectAtIndex:indexPath.row];
    cell.textLabel.text = myAssetModel.name;
   // cell.textLabel.text = @"test";

    return cell;

}

- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{

    if([segue.identifier isEqualToString:@"addAssetSegue"]){
        AddAssetTVC *addAssetTVC = segue.destinationViewController;
        addAssetTVC.delegate = self;

        UIStoryboardPopoverSegue* popoverSegue = (UIStoryboardPopoverSegue*)segue;
        [addAssetTVC setPopoverController:[popoverSegue popoverController]];

    }

}

- (void) theSaveButtonOnTheAddAssetTVCWasTapped:(AddAssetTVC *)controller{
    [controller.navigationController popViewControllerAnimated:YES];
    [self reloadCache];
    [self.tableView reloadData];
    [self viewDidLoad];
}

And the method of saving the type of add:

- (IBAction)save:(id)sender{
    [popoverController dismissPopoverAnimated:YES];
    NSLog(@"Telling the ADDASSET Delegate that Save was tapped on the AddAssetTVC");

    {...unrevelant coredata methods}

    [self.delegate theSaveButtonOnTheAddAssetTVCWasTapped:self];
}

Thanks for reading,

Alexander

+5
source share
4 answers

I had the same problem. I solved it using a special session. In the class method prepare:

  • Take a source view controller, which is either a custom controller or UITableViewController
  • Target Controller Capture
  • Create UIPopoverControllerinitialized by the destination controller
  • Get cell of current selected row
  • Store the popover as a property on the destination controller (this way you can fire it and it won't be freed)
  • popover, frame, CGRect
  • popover,

:

UITableViewController *tvc = (UITableViewController *)self.sourceViewController;
DetailsViewController *details = (DetailsViewController *)self.destinationViewController;    
UITableViewCell *cell = [tvc.tableView cellForRowAtIndexPath:[tvc.tableView indexPathForSelectedRow]];

UIPopoverController *pop = [[UIPopoverController alloc] initWithContentViewController:details];

details.popoverController = pop;

CGSize size = CGSizeMake(640, 460);
pop.popoverContentSize = size;


[pop presentPopoverFromRect:cell.frame
                     inView:tvc.tableView 
   permittedArrowDirections:UIPopoverArrowDirectionUp | UIPopoverArrowDirectionDown 
                   animated:YES];
+4

. :

  • . , . ( ). . Organizer , , didSelectRowAtIndex performSegueWithIdentifier... ...
  • Popover. , Popover
  • Segue Segue, : "SegToDetail".
  • Now in the Master / Parent code with a table view, add a method, didSelectRowAtIndex ... In this method, you can set what the button looks like. The most important thing that you call: [self performSegueWithIdentifier: @ "SegToDetail" ... And here it is ...
  • Now you can pass any information in the prepareForSegue methods, as in any segue transition.
0
source

Based on @Rich's answer, but with PopoverPresentationControllerand in Swift.

override func perform() {
    let svc = self.sourceViewController as! yourSourceViewController
    let pvc = self.destinationViewController as! yourPresentedViewController

    // Present the view controller using the popover style
    pvc.modalPresentationStyle = UIModalPresentationStyle.Popover
    svc.presentViewController(pvc, animated: true, completion: nil)

    // Get the popover presentation controller and configure it
    let cell = svc.tableView.cellForRowAtIndexPath(svc.tableView.indexPathForSelectedRow!)
    let presentationController = pvc.popoverPresentationController
    presentationController!.permittedArrowDirections = .Any
    presentationController!.sourceView = svc.tableView
    presentationController!.sourceRect = cell!.frame
}
0
source

All Articles