So I'm making a static library for iOS. Basically I want people to be able to call something like this:
[MyStaticLibrary showview]
And my static library to add a subview to their current view. No开发者_如何学Pythonrmally I might do something like this:
CGRect mainframe = [[UIScreen mainScreen] bounds];
UIView *mView = [[UIView alloc] initWithFrame:mainframe];
//Add some stuff to the view
[self.view addSubview:mView];
But xcode is complaining, and rightfully so, that I can't access self.view from the static library since I'm currently using an NSObject in my static library. Is there anyway for me to access the "self.view" from my static library so I can add a view to the application screen?
1) You could adapt your showview
method to be showViewInParentView:
and allow the caller to give you the view you need.
2) You could use [[[UIApplication sharedApplication] keyWindow] addSubview:mView]
to add the library's view directly to the window, ensuring that it is on top.
I recommend #1 over #2.
精彩评论