I’m creating a dynamic number of buttons(eventually, these will be placed inside a horizontal scroll view), and I’m displaying a popover when a button is pressed, but I need to set the popover to appear just to the right of the selected button, but at the moment, the popover appears at the same place every time…
This is what I’m trying:
for (int i=0; i < 10; i++) {
childButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
childButton.frame = CGRectMake(100*i, 170, 100, 30);
[childButton setTitle:@"Test" forState:UIControlStateNormal];
[childButton addTarget:self action:@selector(presentPopoverMenu) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:childButton];
}
Ultimately I’m going to create two rows of images, but this is just for testing…
-(void)presentPopoverMenu/*:(id)sender*/
{
MenuPickerController *mp = [[MenuPickerController alloc] init];
popoverMenu = [[UIPopoverController alloc] initWithContentViewController:mp];
popoverMenu.popoverContentSize = CGSizeMake(290, 300);
[popoverMenu presentPopoverFromRect:[childButton bounds]
inView:childButton
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:NO];
}
I’m thinking that it’s probably just taking the value from last button, but I’m not sure, how I would do this otherwise…
Of course it uses last button value, because your ivar
childButtonpoints on it. Take notchildButtonbutsender. Uncomment it and use. Also selector will be@selector(presentPopoverMenu:).