Bronze challenge questions


#1

This challenge gave me a lot of trouble. I think one of the things that I still don’t understand is why you need to use presentPopoverFromRect:inView:permittedArrowDirections:animated:, when I was trying to use presentPopoverFromBarButtonItem:permittedArrowDirections:animated:.

Why does the first one work, and the second crashes my app? I thought it had to do with not setting the size of the popover view, but popoverContentSize didn’t fix it.

The console error I get is [quote] ‘NSInvalidArgumentException’, reason: ‘-[UIRoundedRectButton view]: unrecognized selector sent to instance 0x74cf170’[/quote] What does that mean?

The other thing I couldn’t figure out was how to have only one assetType selected at a time. Once the popover was open, you could select multiple assetTypes, instead of just one. How do you do that?

Lastly, how do you have the popover be the size of its contents? The way I have it, the popover is very long, and it has only 3 elements. Is there a way so that the popover varies in size, depending on how many elements it has? I guess you could calculate it based on the size of the array of items, and the size of the cells, but is there a better way of doing so?

Thanks


#2

The parameter on these methods tells the popover where to “anchor” itself and what to point the arrow at.

presentPopoverFromBarButtonItem:permittedArrowDirections:animated:
can be used only if the control that triggered the popover is a BarButtonItem.

If you don’t have the popover triggered by a BarButtonItem then you have to use
presentPopoverFromRect:inView:permittedArrowDirections:animated:
and you have to decide what object in the view you want the popover arrow to point to. Normally that will be the control that triggered the popover.