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

本文是小编为大家收集整理的关于使用iOS模块构建本地视图并在Titanium中使用它们的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

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

到目前为止,我创建了一个模块,其中可以通过非图形数据,但是从我的模块中获取视图控制器呢.

我已经检查了appcelerator wiki,但这没有任何帮助的教程,引导我会有所帮助

推荐答案

签出TimoddevguideeMoview.h/m和timoddevguidemoviewproxy.h/m在iOS的Mod Dev指南中:

https://github.com/appcelerator/titanium_modules/树/主/moddevguide/mobile/ios/classes

简单地说明了视图和视图代理之间的关系.在这种情况下,它是一个正方形.

您可以在此处查看JavaScript中使用: https://github.com/appcelerator/titanium_modules/blob/master/moddevuide/mobile/ios/example/demos/viewproxydemo.js

一旦你在手中,可以制作一个简单的观点,你可以拿走下一步来解决你的问题.您需要将xib转换为nib.最简单的方法是将xib添加到本机项目,编译项目,然后拔出nib.将其转储在模块的资产中,然后从模块代码中引用它.不幸的是,没有任何使用尖端链接到的公共来源,但我可以向您展示片段. (我们维护此方法的许多模块,所以我知道您可以成功地工作!Jira,Gigya,城市飞艇等.)

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

请注意,除非我们从迫使我们的第三方拥有一些东西,否则我们通常不会使用尖端.只需创建视图而不是声明方式更容易.

您可以在iOS Mod Dev指南中阅读更多有关视图和查看代理.一旦了解在Mod Dev指南(并成功创建自己)上面所关联的内容,Mod Dev指南对您将更有用. (我已经在管道中有一些更新,以便顺便说一下,它将更容易理解). http://docs.appcelerator.com/titanium/2.0/index .html#!//guide/ios_module_development_guide

希望这有帮助.如果有任何我可以进一步肉体的东西,请告诉我.有一个小驼峰对你来克服,但是一旦你把一些肘部油脂放进,你就会通过模块开发来全速运行.

本文地址:https://www.itbaoku.cn/post/1938171.html

问题描述

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

推荐答案

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.