1
votes

edit: solved. see my comment why.. sorry this mess, not able to post an answer myself yet as a newbie..

iPad App: I have a table view and instantiate from the accessoryView a popover with another tableview. in the popover I want to select a cell and pass that index back to the rootView.

I implemented a protocol in PopoverController and conform RootViewController to it.

Why is that backPopover method in the root view not being called?

Any hint much appreciated!!

Edit: That storyboard reference points to a navigation controller. The popover itself works fine..

RootViewController.h

#import "PopoverViewController.h"


@interface rootViewController : UITableViewController <UIPopoverControllerDelegate, UITableViewDelegate, AddDelegate>
{
    UIPopoverController *popOverController;
}

@property (nonatomic, retain) UIPopoverController *popOverController;
@property (nonatomic) PopoverContent *popoverContent;

RootView.m

-(void) backPopover:(int)index
{
    NSLog(@"index sent:%i", index);
    [popOverController dismissPopoverAnimated:YES];
}


// accessoryView Button
- (void) popOver:(UIButton*)paramSender
{
    UITableViewCell *cell = (UITableViewCell*)paramSender.superview;
    if (cell != nil)
    {

        //Table position for popover
        UIButton *button = (UIButton *)cell.accessoryView;

            if(![self popoverContent])
            {
                popoverContent = [[self storyboard]instantiateViewControllerWithIdentifier:@"PopoverContent"];
                [popoverContent setDelegate:self];
                popOverController = [[UIPopoverController alloc]initWithContentViewController:popoverContent];
                popOverController.popoverContentSize = CGSizeMake(320.0, 600.0);
                [popOverController setDelegate:self];
            }

        CGRect rect = button.frame;
        [popOverController presentPopoverFromRect:rect inView:cell permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    }
}

PopoverController.h

@protocol AddDelegate <NSObject>

- (void)backPopover: (int)index;

@end

@property (nonatomic, weak) id <AddDelegate> delegate;

PopoverController.m

@synthesize delegate;


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

    [self.delegate backPopover:indexPath.row];

}
2
popovercontroller is supported only in iPad.Bharathi D
i'm such an idiot I didn't mention, it is a n iPad app.. Big sorry!!L00ps
The problem was that storyboard reference, it actually pointed to a navigation controller.. Removed it, above code works like a charm. Actually, I don't know why I put it there in the first place.. I love how I looked for my answer for hours (days?) ..and in the proccess of learning how to ask here and re-edit my post several times, I came to the solution myself.L00ps

2 Answers

0
votes

Please try this.

MyViewController *viewController=[[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil]; 
UIPopoverController* aPopover = [[UIPopoverController alloc]
                        initWithContentViewController:popupController];
0
votes

The problem was that storyboard reference, it actually pointed to a navigation controller. Above code works like a charm.