Storyboard UIImagePicker overlay UIButton does not

2019-08-28 08:47发布

问题:

update 2

viewDidAppear is executed twice, once before and once after, the overlay button is touched. Would a fix be to add a conditional to viewDidAppear which would return control to the calling class? If so, I would appreciated suggestions. Or maybe the very fact that viewDidAppear execute twice suggests another approach to a fix?

update 2

update 1

Maybe the problem is my usage of viewDidAppear and viewDidLoad shown below. Can anyone help, please?

- (void)viewDidAppear:(BOOL)animated
{

    self.overlayViewController = [[BSsetupOverlayViewController alloc] initWithNibName:@"BSsetupOverlayViewController" bundle:nil] ;

    // as a delegate we will be notified when pictures are taken and when to dismiss the image picker
    self.overlayViewController.delegate = self;


    [self showImagePicker:UIImagePickerControllerSourceTypeCamera];

}


- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

update 1

update 0

Perhaps I was not clear that the difference between the version that does not work and the one that does is that Storyboard is used in the one that does not work. Why would a done button work without Storyboard, but not with, even though only a nib is involved with the overlay?

update 0

The UIButton here was able to dismiss the camera preview, but in my actual app, tapping the UIButton only temporarily dismisses the preview and overlay screen. Immediately the preview returns. I think the problem is with the way I am implementing the delegate to the UIImagePicker, but I may be wrong.

I have created setup.zip here which contains a sample project with the undesirable behavior.

回答1:

I took this question to the North Atlanta iOS Meetup and suggested that a conditional clause might fix the problem, as I mentioned in update 2 of the question. The founder of the Meetup, Kurt Niemi, quickly showed how to do so by editing the BSsetupViewController class.

First he added a Boolean property to the interface.

@property (nonatomic, assign) BOOL alreadyDisplayed;

Second he added a clause to the viewDidAppear method.

if (self.alreadyDisplayed)
{
    self.alreadyDisplayed = FALSE;
    [self dismissViewControllerAnimated:NO completion:nil];
    return;

}

self.alreadyDisplayed = TRUE;

And last he added a slight unnecessary clause to the viewDidLoad method.

self.alreadyDisplayed = FALSE;

I still wish these steps were unnecessary, but they seem to work.