سؤال

لقد أضفت بعض الأزرار إلى الجانب الأيمن من شريط التنقل مع ما يلي:

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

أعتقد أن هذا سيحل مشكلتك

نصائح أخرى

جرب هذا:

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

يعمل كالسحر

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top