Reputation: 1
I have a class which is derived from window controller with xib which has all the functionalities. In this xib i have a tableview which displays the list of halls. If i double click on a hall name, i ll get a popover, which displays the features of that hall. I have a view controller class, in which i would ilk to create the pop over programatically,
NSPopover *popover;
NSViewController *popoverViewController;
-(void)displayPopover{
popover = [[NSPopover alloc] init];
[popover setBehavior: NSPopoverBehaviorApplicationDefined];
[popover setDelegate: self];
popoverViewController = [[CHBPopover alloc] initWithNibName: @"MYViewController" bundle: nil];
[popover setContentViewController: popoverViewController];
[popover setContentSize: popoverViewController.view.frame.size];
[popover showRelativeToRect: NSMakeRect(700, 400, 5, 5)
ofView: [[NSApp keyWindow] contentView]
preferredEdge: NSMaxXEdge];
}
In my window controller class, i have a method like,
-(IBAction)featuresDisplay:(id)sender{
if([_hallNamesList selectedRow] == -1){
[self setFeaturesList:nil];
}
else {
//[self.hallFeaturesPopOver showRelativeToRect:[_hallNamesList frameOfCellAtColumn:0 row:[_hallNamesList selectedRow]] ofView:_hallNamesList preferredEdge:NSMaxXEdge];
// [pop.displayPopover ];
NSDictionary *hallFeaturesDictionary;
hallFeaturesDictionary = [_hallNames objectAtIndex:[_hallNamesList selectedRow]];
_hallId=[hallFeaturesDictionary valueForKey:@"hallId"];
[officeDetails setHallName:[hallFeaturesDictionary valueForKey:@"hallName"]];
_featuresList=[conferenceHall getConferenceHallFeaturesWithDetails:officeDetails];
NSLog(@"features list=%@",_featuresList);
[self setFeaturesList:[conferenceHall getConferenceHallFeaturesWithDetails:officeDetails]];
}
}
How would i call that popover method in this IBAction? I need to double click on a row and display the pop over.. How would i do this? Thanks.
Upvotes: 0
Views: 2672
Reputation: 53542
The display coordinates seem to be quite off. The rectangle for the popover is relative to the ofView parameter. Start with (0, 0) here, which should display the popover in the upper left corner of your keywindow.contentView. Then fine tune the position. You probably have to pass in the actual rectangle from your IBAction (probably the table cell bounds). The size part in the view rect for the popover is important because the popover moves relative to that. I'd also pass in the view to attach the popover to, as sometimes a view does not become key when you click it.
Note that the delegate for the popover is only necessary if you plan to implement detaching it into a floating window. Experiment also with the behavior. Start with NSPopoverBehaviorTransient. I'm not sure what you actually have to do with the application defined behavior but at least with the transient behavior it works fine for me.
Finally, you don't need to recreate the popover every time you show it. Just set it up in awakeFromNib and then just call showRelativeToRect...
every time you need it. With the transient behavior it will automatically disappear.
Upvotes: 1