Amazon.com Widgets Duplicate popover problem (likely a fundamentals issue)
Welcome, Guest. Please login or register.
Did you miss your activation email?
June 18, 2013, 06:16:50 PM
Home Help Search chat Login Register   
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+  Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+  iOS Programming
| |-+  General Questions
| | |-+  Duplicate popover problem (likely a fundamentals issue)
Pages: [1]   Go Down
Print
Author Topic: Duplicate popover problem (likely a fundamentals issue)  (Read 811 times)
MikeP
Newbie
*
Posts: 2






« on: July 12, 2010, 05:44:21 AM »

This is my first app since slogging through the Learning Objective C 2.0 and Beginning iPhone 3 books, so please bear with me.  The response I got on another forum (http://www.iphonedevsdk.com/forum/iphone-sdk-development/52850-cant-seem-stop-duplicate-popovers.html) wasn't helpful at all.  Even if he pointed me to the relevant section of his "definitive guide" that helped explain where I failed and why, that would have helped.

I've got this one user experience bug I just can't seem to shake. You tap a toolbar button and a popover displays. That's good. Tap the toolbar button again and I get a 2nd popover right on top of the first. Not good.
Code: (Objective-C)
		FlickrPhotoPickerController *flickrPhotoPickerView = [[FlickrPhotoPickerController alloc] init];
UIPopoverController *photoPopover = [[UIPopoverController alloc] initWithContentViewController:flickrPhotoPickerView];
[photoPopover setDelegate:self];
[flickrPhotoPickerView setPopover:photoPopover];
[flickrPhotoPickerView setMainImage:PPimageView];
if ([photoPopover isPopoverVisible]) {
NSLog(@"Yep, visible!");
[photoPopover dismissPopoverAnimated:YES];
} else {
NSLog(@"Nope, not visible!");
[photoPopover presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}


[flickrPhotoPickerView release];

The thing is, the if keeps evaluating to false, even if the button is pressed a second time.

If I do this:
Code: (Objective-C)
		if ([photoPopover isPopoverVisible]) {
NSLog(@"Yep, visible!");
[photoPopover dismissPopoverAnimated:YES];
}
FlickrPhotoPickerController *flickrPhotoPickerView = [[FlickrPhotoPickerController alloc] init];
UIPopoverController *photoPopover = [[UIPopoverController alloc] initWithContentViewController:flickrPhotoPickerView];
[photoPopover setDelegate:self];
[flickrPhotoPickerView setPopover:photoPopover];
[flickrPhotoPickerView setMainImage:PPimageView];
 
NSLog(@"Nope, not visible!");
[photoPopover presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];


[flickrPhotoPickerView release];

I get "'photoPopover' undeclared (first use in this function)"

My sense is it's a scope issue for the popover controller, but I'm not sure how to handle the init properly for my needs.  (basically, I understand that I may be failing to understand a basic fundamental concept)

Now, his response was:
Quote
Use a property for the popover. Then dismiss the old popover before you create a new one.


I considered that, but I wasn't getting anywhere there either. Using @property and @synthesize, and changing my code to:
Code: (Objective-C)
		if ([photoPopover isPopoverVisible]) {
NSLog(@"Yep, visible!");
[photoPopover dismissPopoverAnimated:YES];
}
FlickrPhotoPickerController *flickrPhotoPickerView = [[FlickrPhotoPickerController alloc] init];
[photoPopover initWithContentViewController:flickrPhotoPickerView];
[photoPopover setDelegate:self];
[flickrPhotoPickerView setPopover:photoPopover];
[flickrPhotoPickerView setMainImage:PPimageView];
 
NSLog(@"Nope, not visible!");
[photoPopover presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];


[flickrPhotoPickerView release];

No popover would even appear. If I don't use @synthesize, wouldn't I still have to alloc right there where I was before? Wouldn't that leave me back at square one?  Should I be overloading the setter?
Logged
Pages: [1]   Go Up
Print
Jump to:  



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.