开发者

Displaying a view from an arbitrary method on iPhone

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 kno开发者_开发百科w 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.


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


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜