7

I want to build an iOS module in which I have a viewController class with its .xib file. now the problem is how to call that view from my titanium code. I know that there are view proxy available but dont know how to use them due to not so good documentation.

Till now I have created a module where non graphical data can be passed but what about getting View controller from my module.

I have already checked the appcelerator wiki, but that was not helpful Any tutorial that will guide me will be helpful

Ajeet Pratap Maurya
  • 4,244
  • 3
  • 28
  • 46

1 Answers1

5

Check out the TiModdevguideDemoView.h/m and TiModdevguideDemoViewProxy.h/m in the mod dev guide for iOS:

https://github.com/appcelerator/titanium_modules/tree/master/moddevguide/mobile/ios/Classes

It demonstrates simply the relationship between views and view proxies. In this case, it makes a square.

You can see it being used in JavaScript here: https://github.com/appcelerator/titanium_modules/blob/master/moddevguide/mobile/ios/example/demos/viewproxyDemo.js

Once you have that in hand, and can make a simple view, you're ready to take the next step to solving your question. You need to convert your XIB to a NIB. The easiest way is to add the XIB to a native project, compile the project, and then pull out the NIB. Dump it in the assets for the module, and then reference it from your module code. I unfortunately don't have any public source that uses NIBs to link to, but I can show you a snippet. (A number of modules we maintain use this method, so I know that you can successfully get it working! Jira, Gigya, Urban Airship, and others.)

NSBundle* bndl = [NSBundle bundleWithPath:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"ti.jira/1.0/assets/JMC.bundle"]];
JMCSketchViewController *sketchViewController = [[[JMCSketchViewController alloc] initWithNibName:@"JMCSketchViewController" bundle:bndl] autorelease];

Note that we usually don't use NIBs unless we have something from a third party that forces us to. It's easier just to create the views imperatively rather than declaratively.

You can read more about views and view proxies in our iOS mod dev guide. Once you understand what I linked above in the mod dev guide (and successfully create your own), the mod dev guide will be much more useful to you. (I've got some updates to the guide in the pipeline that will make it easier to understand, by the way). http://docs.appcelerator.com/titanium/2.0/index.html#!/guide/iOS_Module_Development_Guide

Hope this helps. Let me know if there's anything I can further flesh out. There's a small hump of understanding for you to get over, but once you put some elbow grease in, you'll be running full speed with module development.

Dawson Toth
  • 5,580
  • 2
  • 22
  • 37
  • ,Thanks for your answer, as you said the `convert your XIB to NIB`, here I am not creating just a xib file. I am adding a whole UIViewController with the .h,.m, and .xib file. And if I want to add a functionality with a view to my titanium project, so I will be adding a viewController with a .xib attached to it. – Ajeet Pratap Maurya May 14 '12 at 06:46
  • Hi Dawson, I am still struggling with the native module development, I got success with non visual data but when it comes to creating a view from native module I am still in dark.. can you help me with any tutorial. – Ajeet Pratap Maurya Jun 14 '13 at 11:10
  • Have you looked through the public modules? -- https://github.com/appcelerator/titanium_modules -- QuickLook, PageFlip, Tandem Scroll, Styled Label, Paint, Columns, Charts, and others all have visual components. – Dawson Toth Jun 14 '13 at 17:43
  • thanks I will see through it.. if any problem, I will get in touch with you.. :) – Ajeet Pratap Maurya Jun 14 '13 at 18:14
  • I gone through the list of module and even your paint module. I am very well understanding the ios code but I am still confused with the linking of it and titanium.. may be I am missing something. If you can share a tutorial with small and crucial details, then it be really great. – Ajeet Pratap Maurya Jun 26 '13 at 11:49
  • You should open another question asking for help with the precise problem you're having. "confused with the linking of it and Titanium" is too vague. – Dawson Toth Jun 27 '13 at 15:51