Skip to content

Right way to create BarButtonItem tips #9

@anuchandra

Description

@anuchandra

I'd like to add a tooltip pointing to the right BarButton in the Navigation bar. I can't seem to figure out the right approach.

I've tried this but it doesn't work. I can't get a pointer to the host view. It seems the targetview is nil.

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self loadObjects];
    UIBarButtonItem *rightBarButtonItem = self.navigationItem.rightBarButtonItem;
    UIView *targetView = [self.navigationItem.rightBarButtonItem valueForKey:@"view"];
    UIView *targetSuperview = [targetView superview];
    UIView *containerView = [targetSuperview superview];

    if (nil == containerView) {
        NSLog(@"Cannot determine container view from UIBarButtonItem: %@", self.navigationItem.rightBarButtonItem);
        return;
    }
    JDFTooltipView *tooltip = [[JDFTooltipView alloc] initWithTargetBarButtonItem:self.navigationItem.rightBarButtonItem hostView:containerView tooltipText:@"Right bar button" arrowDirection:JDFTooltipViewArrowDirectionDown width:200.0f];
    [tooltip show];
}

So I tried a different way to get the view for UIBarButtonItem but again the targetview is nil.

UIView *targetView = (UIView *)[self.navigationItem.rightBarButtonItem performSelector:@selector(view)];

I even tried getting the view this way but no luck there either.

UIView* customview = [self.navigationItem.rightBarButtonItem customView];

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions