Reputation: 2499
I have a small problem. I am working on an iPad app and in that I've a UItableView. Inside that table there are buttons in every cell at perfect position. Now, when the user clicks on those buttons I wish to open a UIImagePickerView so that he can select image and set it there.
Now, I am using UIPopOver's object to open the imagePicker and there is where I face the problem. I need the popOver to point at the perfect place to which button clicked it. Suppose the button from the 3rd row in the table calls it then the popOver should open accordingly.
I am using this code to open the popOver and set its frame:
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.delegate = self;
CGRect fr = tblView.frame;
fr.origin.x = fr.origin.x + btnActive.frame.origin.x;
fr.origin.y = fr.origin.y + btnActive.frame.origin.y;
fr.size = CGSizeMake(320, 480);
popOver = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
//self.popoverController = popOver;
popOver.delegate = self;
[popOver presentPopoverFromRect:btnActive.frame
inView:tblView
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
[imagePicker release];
Now, here what happens is, whenever I click the rows of the button, the popOver points at the first visible row only. I call a method called - (void) setImage: (id) sender
when user clicks on any of those buttons in the TableView. And I assign the button btnActive as follows:
UIButton *btn = (UIButton *)sender;
btnActive = btn;
I get the tag of the button perfectly but I am not able to get the popOver point at the perfect place. I guess that is because every time the frame of btnActive remains the same. I might be wrong. Please help me with this issue. A million thanks in advance!
Upvotes: 0
Views: 677
Reputation: 7720
tblView
isn't the button's superview. try using cell.contentView
or cell
depending on how you have the UITableViewCell subclass view hierarchy laid out. You'll have to determine which cell the button was clicked in.
[popOver presentPopoverFromRect:btnActive.frame
inView:cell.contentView
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
Upvotes: 1