Is it possible to perform a Popover Segue manually (from dynamic UITableView cell)?

后端 未结 4 854
隐瞒了意图╮
隐瞒了意图╮ 2020-12-14 01:09

I need to perform a Popover segue when user touches a cell in a dynamic TableView. But when I try to do this with this code:

- (void)tableView:(UITableView *         


        
4条回答
  •  情歌与酒
    2020-12-14 01:33

    Just adding this answer as an alternative way to present a popover from a touched cell, though it uses code rather than a segue. It's pretty simple though and has worked for me from iOS 4 through iOS 7:

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        [tableView deselectRowAtIndexPath:indexPath animated:NO];
    
        //get the data of the row they clicked from the array
        Url* clickedRec = [self.resultsArray objectAtIndex:indexPath.row];
    
        //hide the popover in case it was already opened from a previous touch.    
        if (self.addNewPopover.popoverVisible) {
                [self.addNewPopover dismissPopoverAnimated:YES];
                return;
            }
    
        //instantiate a view controller from the storyboard
        AddUrlViewController *viewControllerForPopover =
        [self.storyboard instantiateViewControllerWithIdentifier:@"addUrlPopup"];
    
        //set myself as the delegate so I can respond to the cancel and save touches.
        viewControllerForPopover.delegate=self;
        //Tell the view controller that this is a record edit, not an add        
        viewControllerForPopover.addOrEdit = @"Edit";
        //Pass the record data to the view controller so it can fill in the controls            
        viewControllerForPopover.existingUrlRecord = clickedRec;
    
        UIPopoverController *popController = [[UIPopoverController alloc]
                                              initWithContentViewController:viewControllerForPopover];
    
        //keep a reference to the popover since I'm its delegate        
        self.addNewPopover = popController;
    
        //Get the cell that was clicked in the table. The popover's arrow will point to this cell since it was the one that was touched.
        UITableViewCell *clickedCell = [self.tableView cellForRowAtIndexPath:indexPath];
    
        //present the popover from this cell's frame.
        [self.addNewPopover presentPopoverFromRect:clickedCell.frame inView:self.myTableView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    }
    

提交回复
热议问题