0

I have a problem with the implementation of FPPopover library.

I have a similar issue than on an other post : Same issue on StackOverFlow

Unfortunately, a reference to the popover controller does not fix my problem.

On my future controller, I have an UITableView dynamically loaded when the action button is clicked. This is my code:

- (IBAction)displayAlternateNicknames:(id)sender{
  PXAlternativeNicknamesViewController * suggestionsVC=    [[UIStoryboard storyboardWithName:[ViewsParamsSingleton sharedLoginSignUpStoryBoard] bundle:nil] instantiateViewControllerWithIdentifier:NicknameSuggestionsStoryBoardID];
  suggestionsVC.title=@"Suggestions";
  suggestionsVC.nicknameSuggestions=self.nicknameSuggestions;
  suggestionsVC.callerVC=self;

  //our popover
  suggestionsPopover = [[FPPopoverController alloc] initWithViewController:suggestionsVC];

  suggestionsPopover.contentSize = CGSizeMake(200,200);

  //the popover will be presented from the okButton view
  [suggestionsPopover presentPopoverFromView:sender];
}
Community
  • 1
  • 1
brcebn
  • 1,571
  • 1
  • 23
  • 46
  • Do you have a strong reference to suggestionsPopover? (i.e. @property (nonatomic, strong) FPPopoverController *suggestionsPopover) – ebandersen Apr 14 '14 at 14:45
  • No I didn't but even with `@property (strong,nonatomic) FPPopoverController * suggestionsPopover;` it still not working. – brcebn Apr 14 '14 at 16:59
  • K, I haven't worked with FPPopoverController in awhile, but I'll post an answer below with what has worked for me in the past. – ebandersen Apr 14 '14 at 17:10

1 Answers1

0

Here's my implementation that's working in production. Try this out. It may just be that you haven't set all the properties correctly.

// MyViewController.m
@interface MyViewController ()

@property(nonatomic, strong) FPPopoverController *popover;

@end

...

// Instantiate popover

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
LoginViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];

if (self.popover) {
    [self.popover dismissPopoverAnimated:NO];
    self.popover = nil;
}

self.popover = [[FPPopoverController alloc] initWithViewController:viewController];
self.popover.contentSize = viewController.size;
self.popover.border = NO;
self.popover.arrowDirection = FPPopoverNoArrow;
self.popover.tint = FPPopoverRedTint;

[self.popover presentPopoverFromView:self.loginButton];

If the problem persists, I found another answer here that might help. Essentially, you'd have to disable ARC for FPPopover. I'm not sure how to do this with Cocoapods so you may have to just copy-and-paste the library directly into your project instead. I know it's not an ideal solution, but I think it's worth a shot.

Yet another possibility is to create an instance variable of your FPPopover and reference it that way. Example:

@property (nonatomic, strong) FPPopover *popover;
...
- (FPPopover *)popover {
    if(!_popover){
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
        LoginViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];

        _popover.contentSize = viewController.size;
        _popover.border = NO;
        _popover.arrowDirection = FPPopoverNoArrow;
        _popover.tint = FPPopoverRedTint;
    }
    return _popover;
}
...
-(void)buttonTapped:(UIButton *)sender{
    [self.popover presentPopoverFromView:sender];
}
ebandersen
  • 2,362
  • 26
  • 25
  • It is not working. On the terminal I can read that : `FPPopoverController dealloc`, `FPTouchView dealloc` and `FPPopoverView dealloc`. Can you show me your reference of `popover` on the .m and .h if necessary ? Thank you ! – brcebn Apr 14 '14 at 17:49
  • I just edited my answer. The only other place it's references is in the.m's interface – ebandersen Apr 14 '14 at 17:53
  • THank you for this addition. I've tried exactly your code inside the action of UIButton but it's not working. I have no idea of the reason. Is it normal to have these alerts on my terminal ? – brcebn Apr 14 '14 at 18:19
  • Well, it's 'normal' when it's not working ... haha. The issue probably is that your suggestionsPopover is being dealloced before it's being presented... thus, it shows nothing (and thus my suggestion about the strong reference). – ebandersen Apr 14 '14 at 18:28
  • So, in essence, you're going to have to look a little deeper into why it's being dealloced. – ebandersen Apr 14 '14 at 18:29
  • Finally the problem is not solved. I had to reinstall CocoaPods and now I have the same problem again. My `FPPopoverController` is delloc just after being alloc. I don't have any idea of the reason. – brcebn Apr 25 '14 at 06:49
  • I just edited my original answer with another suggestion. You could always try copy-and-pasting the library in directly and then disabling ARC... – ebandersen Apr 25 '14 at 16:13
  • I have found something stranger. The first time I use the `alloc` the `FPPopoverController` is not `dealloc` just after the allocation. The happens only on the second click. After this click, each allocation is followed by a deallocation. Nevertheless, on the first click there isn't any `dealloc` but nothing happens. By the way, I would like to avoid copying the whole code in my own. – brcebn Apr 28 '14 at 07:23
  • I understand. If it doesn't dealloc on the first click you should try subclassing it into a Singleton. That way you can alloc it once and keep it throughout the lifetime of your project. It may add slightly to your overall memory usage but it's another thought that might solve your problem. – ebandersen Apr 28 '14 at 12:37
  • Do you know a good example to do what you've just said ? Currently I'm not able to try it. Thank you in advance. – brcebn Apr 29 '14 at 06:01
  • Before you create a Singleton, try this: – ebandersen Apr 30 '14 at 03:15
  • Create an instance method of FPPopover (ex: @property (nonatomic, strong) FPPopover *popover) – ebandersen Apr 30 '14 at 03:16
  • I have a little problem: my controller is not the same each time. That means my allocation of `FPPopoverController` is not the same on each button. I can't use this way to solve my problem. Actually, I think I have to instantiate a new one each time. – brcebn Apr 30 '14 at 06:50
  • Good point. Then the singleton pattern won't work for you either then – ebandersen Apr 30 '14 at 12:27