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

查看:28
本文介绍了使用 iOS 模块构建原生视图并在 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.

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

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 模组开发指南中的 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/树/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 模块构建原生视图并在 Titanium 中使用它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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