4

我在导航栏的右侧添加了一些按钮,如下所示:

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];

这很好用。对于这两个按钮,我都显示了一个 popOver,如下所示

- (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 ,这显示了两个按钮中间的顶部箭头。如何将箭头附加到每个按钮?

4

2 回答 2

8

而不是使用这一行:

aPopover presentPopoverFromBarButtonItem:self.navigationItem.rightBarButtonItem

你最好试试这条线:

aPopover presentPopoverFromBarButtonItem:sender

我认为这会解决你的问题

于 2011-04-23T09:35:32.707 回答
5

试试这个:

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

奇迹般有效

于 2012-03-06T15:42:33.897 回答