iPhone: Error when using the FPPopover class when using it with a UIBarButtonItem

后端 未结 4 1119
野的像风
野的像风 2021-01-11 10:19

I am using the FPPopover class which creates popups for iPhones. I followed the exact steps that are in the readme file but instead of using a UIbutton from a xib file, I am

4条回答
  •  自闭症患者
    2021-01-11 10:53

    I was getting the same error. Solution is to create a UIButton Programatically (at the same place of UIBar button item - set the appropriate coordinates) and then present popover from UIButton. Then hide the UIButton.

    This code worked for me:

    -(void)testMethod {
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    
    // set action as NULL if you dont need any method/functionality to call
    
    [button addTarget:self action:@selector(aMethod)
     forControlEvents:UIControlEventTouchDown];
    
    
    [button setTitle:@"Show View" forState:UIControlStateNormal];
    button.frame = CGRectMake(130, -40, 160.0, 40.0);
    [self.view addSubview:button];
    
    AlertsViewController *controller = [[AlertsViewController alloc] init]; 
    
    //our popover
    FPPopoverController *popover = [[FPPopoverController alloc] initWithViewController:controller]; 
    
    //the popover will be presented from the Button view 
    [popover presentPopoverFromView:button]; 
    
    //hide the button
    button.hidden = YES;
    
    }
    
    -(void)aMethod {
    // Write any functionality if you need
    }
    

    Hope this helps. Let me know if you get any issue.

提交回复
热议问题