How to create a Module in Xcode with a View for Titanium Mobile?
Hello,
i've studied the
http://developer.appcelerator.com/doc/mobile/iphone/module_sdk
but still did not managed to get a custom module with its own view to run.
Could anyone provide a simple example, please?
That would be helpful for the whole Titanium community, i guess ;)
Thank you in advance.
My specific problem:
My Module inherits from TiModule. To display a modal view is need to call presentModalViewController, but this method is only available if inherited from UIViewController. Anyone an idea, how to make this working for Titanium?
4 Answers
-
Accepted Answer
Finally figured this out. You don't have access to the current view controller, but you do have access to the app delegate, and it has a showModalController method that handles figuring out the view context for you. In this case, where "reader" was a view controller subclassed from UIImagePickerController, we used the following:
[[TiApp app] showModalController:reader animated:YES];
Note: we had to make sure the module (in ComDevelopmentnowTestModule.h) had implemented a couple protocols, like so:
@interface ComDevelopmentnowTestModule : TiModule <UINavigationControllerDelegate, UIImagePickerControllerDelegate>
And we had to have these lines before that in the function, to make sure that the function has access to the UI thread and the controller knows where to delegate.
ENSURE_UI_THREAD(functionName,args); [reader setDelegate:self];
Finally, to DISMISS the modal view when we got what we wanted, we had to do so by addressing it rather than the app:
[reader dismissModalViewControllerAnimated: YES];
You may not need all this if you're not doing the same thing we did. Good luck!
-
We're having exactly this problem right now–[self parentViewController] and [[TiApp app] parentViewController] aren't it, apparently. The documentation on ViewProxies is wildly out of date. We'd be grateful if anyone can provide an answer, and we'll definitely post one here ourselves if we figure it out.
-
That guide is our most current documentation on SDK module development. If you're struggling to get a module running, you can try swinging by #titanium_dev on irc.freenode.net - this is the channel for people working on Titanium internals and extensions. You might be able to catch one of the devs there as well.
-
Thank you for your answer Kevin. We will of course follow your advice and ask on irc. But nevertheless i try to precise my question, maybe to help some other developers as well.
Question:
How to get access to current viewcontroller from within TiModule for creating new subviews.Thank you.