2011-12-30 8 views
4

私はUITableViewCellの中にUIButtonを持っています。ユーザーがセルのボタンをタッチすると、ボタンを指し示すUIPopoverControllerが表示されます。私は(デリゲートはのUITableViewを所有するビューコントローラである)セルのデリゲートに次のコードを持っている瞬間UITableViewCell内のオブジェクトを指すUIPopOverController?

:このコードで

-(void) onStatusButtonTouched:(UIButton *)aButton{ 
    StatusPickerController *statusPicker = [[StatusPickerController alloc] init]; 

    _popOver = nil; 
    _popOver = [[UIPopoverController alloc] initWithContentViewController:statusPicker]; 

    [_popOver setDelegate:self]; 

    [_popOver presentPopoverFromRect:aButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES]; 
    [_popOver setPopoverContentSize:CGSizeMake(100, 352)]; 
} 

ポップオーバーはいつもの上部に向いていますボタンのyの位置はセルとの相対的な位置にあるため、

私の質問は、それを指すためにボタンの絶対位置を知ることができますか?それを解決する方法はありますか?ボタンのフレームには、ボタンのスーパーの座標系である:代わりに次の行の

答えて

8

[_popOver presentPopoverFromRect:aButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES]; 

はAadhiraによって答えに少しを展開するには、以下の行

[_popOver presentPopoverFromRect:aButton.frame inView:[aButton superview] permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES]; 
+0

ありがとう、これは正しい答えです。 –

+0

答えが正しければ、それを愛する、ありがとう! – Tim

+0

@Tim、いつでも歓迎です! – Ilanchezhian

2

を試してみてください。それをself.viewに入れるには、self.viewの座標系に変換する必要があります。これは、このように、UIViewの方法convertRect:(CGRect) toView:(UIView *)を使用して行うことができます。

CGRect presentFromRect = [self.view convertRect:aButton.frame fromView:aButton.superview]; 
[_popOver presentPopoverFromRect:presentFromRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES]; 

popoversを使用している場合、これは非常に一般的な状況であるため、Appleがショートカットを提供します。これはAadhiraが与えた答えです。

+0

convertRect :(CGRect)toViewのヒントをありがとう:(UIView *) –

関連する問題