Building Native View using iOS module and using them in Titanium

夙愿已清 提交于 2019-12-04 13:19:49

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/10480211/building-native-view-using-ios-module-and-using-them-in-titanium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!