tags:

views:

27

answers:

3

I'm pulling together a few utility methods for testing and I'd like to be able to pop up a view from within an arbitrary method - one that doesn't necessarily know about any UIViewControllers or windows. Is this possible?

For example I'm preparing a custom location manager shim so that I can manually inject location data when I'm testing. I'd like some of the methods to pop up a MKMapView to allow me to select the "current location" instead of manually entering lat/long values in code.

+1  A: 

I think that it is possible, even that I don't exactly know how to do it. The reason I know that this is possible because I see FBConnect of Facebook and DDSocialLoginDialog Library do what you are describing.

The source code and architecture of FBConnect is quite complex but DDSocialLoginDialog is easy to get and pull out the source code you need ( 2 classes with 4 files and few hundred lines of code) . Both are open source. Then, I hope that you can modify the source code so that it can add the MKMapView as a subview

vodkhang
+1  A: 

Taking @vodkhang's advice I took a peek at the code and created my own category (UIView+ShowThySelf) to pop up any arbitrary view from any method. For those interested it can be found on github

http://github.com/appsinyourpants/Pants-Framework

Paul Alexander
thanks, good job, I will need them sometimes:)
vodkhang
+1  A: 

Summary of the previously mentioned methods, in case you want to roll your own code:

Create a UIControl. Write a method to dismiss that control, and add it as a target to that control. Place the view you want to pop up inside that control as a subview. Use:

[UIApplication sharedApplication] keyWindow]

or (in the rare case your app has more than one window, such as VGA cable support):

[[[UIApplication sharedApplication] windows] objectAtIndex: 0]

to find a place where to add a subview (the control you created). Add it.

hotpaw2