First, I would like to say that I am really new to the development of ipad / ipod / iphone, as well as to objective-c.
With that said, I'm trying to develop a small iPad-oriented application using Xcode and IB, basically, I have a table for each UITableViewCell in the table, I added a button containing an image to the accessory.
Here is the code:
UIImage *img = [UIImage imageNamed:@"myimage.png"];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
CGRect frame = CGRectMake(0.0, 0.0, img.size.width, img.size.height);
button.frame = frame;
[button setBackgroundImage:img forState:UIControlStateNormal];
[button addTarget:self action:@selector(checkButtonTapped:event:) forControlEvents:UIControlEventTouchUpInside];
button.backgroundColor = [UIColor clearColor];
cell.accessoryView = button;
So far, so good, now the problem is that I want the PopOver control to appear when the user clicks a button on a cell accessory.
I tried this on the "accessoryButtonTappedForRowWithIndexPath" table View:
UITableViewCell *cell = [myTable cellForRowAtIndexPath:indexPath];
UIButton *button = (UIButton *)cell.accessoryView;
customViewController = [[CustomViewController alloc]init];
popOverController = [[UIPopoverController alloc]
initWithContentViewController: customViewController];
popOverController.popoverContentSize = CGSizeMake(147, 122);
CGRect rect = button.frame;
[popOverController presentPopoverFromRect:rect inView:cell.accessoryView
permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
The problem with this code is that it shows a Popover at the top of the View application, and when debugging, I saw the values ββ"rect", and they:
x = 267
y = 13
, , PopOver , : PopOver, ?
, , "cell.accessoryView" "inView:", ?