iPad的酥料饼presentpopoverfrombarbuttonitem

iPad的酥料饼presentpopoverfrombarbuttonitem

问题描述:

我已经添加了几个按钮,用下面的导航栏的右侧:iPad的酥料饼presentpopoverfrombarbuttonitem

UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 44)]; 
customView.backgroundColor = [UIColor clearColor]; 

UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom]; 
button.frame = CGRectMake(0, 0, 45, 44); 
button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter; 
button.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; 
button.backgroundColor = [UIColor clearColor]; 
[button setImage:[UIImage imageNamed:@"toc.png"] forState:UIControlStateNormal]; 
button.userInteractionEnabled = YES; 
[button addTarget:self action:@selector(tableOfContentsAction) forControlEvents:UIControlEventTouchUpInside]; 
[customView addSubview:button]; 

button = [UIButton buttonWithType:UIButtonTypeCustom]; 
button.frame = CGRectMake(50, 0, 45, 44); 
button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter; 
button.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; 
button.backgroundColor = [UIColor clearColor]; 
[button setImage:[UIImage imageNamed:@"bookmark.png"] forState:UIControlStateNormal]; 
button.userInteractionEnabled = YES; 
[button addTarget:self action:@selector(bookmarkButtonAction) forControlEvents:UIControlEventTouchUpInside]; 
[customView addSubview:button]; 

UIBarButtonItem *segmentBarItem = [[UIBarButtonItem alloc] initWithCustomView:customView]; 

self.navigationItem.rightBarButtonItem = segmentBarItem; 
[customView release]; 
[segmentBarItem release]; 

这种运作良好。对于这两个按钮,我表现出酥料饼如下图所示

- (void) bookmarkButtonAction 
{ 
BookmarksViewController* content = [[BookmarksViewController alloc] initWithOrientation:lastOrientation selectedPage:selectedPage]; 
UIPopoverController* aPopover = [[UIPopoverController alloc] initWithContentViewController:content]; 
CGSize size = content.view.frame.size; 
aPopover.popoverContentSize = size; 
aPopover.delegate = self; 
self.bookmarksPopoverVC = content; 
self.bookmarksPopoverVC.popUpController = aPopover; 
[content release]; 
[aPopover presentPopoverFromBarButtonItem:self.navigationItem.rightBarButtonItem permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES]; 
[aPopover release]; 
bookmarksShowing = YES; 
} 

的问题是,我使用presentPopoverFromBarButtonItem:self.navigationItem.rightBarButtonItem,这显示了两个按钮中间的顶部箭头。我怎样才能将箭头附加到每个按钮?的

而不是使用此行:

aPopover presentPopoverFromBarButtonItem:self.navigationItem.rightBarButtonItem 

您可以更好地尝试这一行:

aPopover presentPopoverFromBarButtonItem:sender 

我认为这将解决您的问题

+0

非常感谢您的回答。出于某种原因,我不明白你真的必须使用发件人项目,并且不能使用你自己声明的那个。 – guruz 2012-02-15 15:00:40

试试这个:

- (IBAction)products:(id)sender { 
    UIButton* btn = (UIButton *)sender; 
    [productsPopover presentPopoverFromRect:[btn bounds] inView:btn permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; 
} 

像一个工程魅力