最初に、私は ipad/iPod/iphone の開発と、objective-c の初心者です。
そうは言っても、私は Xcode と IB を使用して、iPad をターゲットとする小さなアプリケーションを開発しようとしています。
コードは次のとおりです。
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; // match the button's size with the image size
[button setBackgroundImage:img forState:UIControlStateNormal];
// set the button's target to this table view controller so we can interpret touch events and map that to a NSIndexSet
[button addTarget:self action:@selector(checkButtonTapped:event:) forControlEvents:UIControlEventTouchUpInside];
button.backgroundColor = [UIColor clearColor];
cell.accessoryView = button;
これまでのところ、問題は、ユーザーがセルのaccessoryViewのボタンをタップしたときにPopOverコントロールが表示されるようにすることです。
tableViewの「accessoryButtonTappedForRowWithIndexPath」でこれを試しました:
UITableViewCell *cell = [myTable cellForRowAtIndexPath:indexPath];
UIButton *button = (UIButton *)cell.accessoryView;
//customViewController is the controller of the view that I want to be displayed by the PopOver controller
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];
このコードの問題は、アプリケーション ビューの上部にポップオーバーが表示されることです。デバッグ中に「rect」の値が表示され、次のようになります。
x = 267
y = 13
なぜ PopOver がビューに表示されているのかは明らかだと思います。私の質問は、PopOver の正しい値をセルのアクセサリビューのボタンのすぐ下に表示するにはどうすればよいですか?
また、ご覧の通り「inView:」属性に「cell.accessoryView」を使うように言っているのですが、よろしいでしょうか?