使用iOS模块构建Native View并在Titanium中使用它们 [英] Building Native View using iOS module and using them in Titanium

查看:71
本文介绍了使用iOS模块构建Native View并在Titanium中使用它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想构建一个iOS模块,其中有一个带有.xib文件的viewController类.现在的问题是如何从我的钛金代码中调用该视图.我知道有可用的视图代理,但是由于文档不够好,所以不知道如何使用它们.

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.

到目前为止,我已经创建了一个可以传递非图形数据的模块,但是如何从模块中获取View控制器呢?

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

我已经检查了appcelerator Wiki,但这无济于事.任何指导我的教程都将有所帮助

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

推荐答案

在iOS的mod开发指南中查看TiModdevguideDemoView.h/m和TiModdevguideDemoViewProxy.h/m:

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.

您可以在此处查看它在JavaScript中的使用情况: https://github.com/appcelerator/titanium_modules/blob/master/moddevguide/mobile/ios/example/demos/viewproxyDemo.js

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

掌握了这些信息并可以进行简单的查看后,就可以准备下一步解决问题了.您需要将XIB转换为NIB.最简单的方法是将XIB添加到本机项目中,编译该项目,然后拉出NIB.将其转储到模块的资产中,然后从模块代码中引用它.不幸的是,我没有任何使用NIB链接到的公共资源,但是我可以向您展示一个片段. (我们维护的许多模块都使用此方法,因此我知道您可以成功地使它工作!吉拉(Jira),吉佳(Gigya),城市飞艇(Urban Airship)等).

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];

请注意,除非我们有来自第三方的强迫我们这样做,否则我们通常不使用NIB.强制性地创建视图比声明性地创建视图要容易得多.

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.

您可以在我们的iOS mod开发指南中阅读有关视图和视图代理的更多信息.一旦您了解了我在mod dev指南中上面链接的内容(并成功创建了自己的链接),mod dev指南将对您有用得多. (顺便说一下,我已经对该管道中的指南进行了一些更新,这将使其更易于理解). http://docs.appcelerator.com/titanium/2.0/index .html#!/guide/iOS_Module_Development_Guide

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.

这篇关于使用iOS模块构建Native View并在Titanium中使用它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆