UIBarButtonItem with UIButton as CustomView - from UIButton, how to access the UIBarButtonItem its in?

前端 未结 5 773
误落风尘
误落风尘 2021-01-05 06:51

I have a UIBarButtonItem with UIButton as custom view.

The UIButton has a addTarget:action: on it. In the action

5条回答
  •  一向
    一向 (楼主)
    2021-01-05 07:40

    Let's say you have added the UIButton aButton to UIBarButtonItem info_Button as following:

    //Add a button on top of the UIBarButtonItem info_button
    UIButton *aButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
    [aButton addTarget:self action:@selector(showInfo:) forControlEvents:UIControlEventTouchUpInside];
    info_Button.customView = aButton;
    

    Now, in showInfo, presentPopoverFromBarButtonItem:info_Button(instead of presentPopoverFromBarButtonItem:sender), this will pass the UIBarButtonItem info_button to make pop over works:

    - (IBAction)showInfo:(id)sender
    {   
        [self.flipsidePopoverController presentPopoverFromBarButtonItem:info_Button   permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    
    }
    

提交回复
热议问题