1

我开发了一个本机模块,它要求我在打开模块控制器时传递一个视图。该模块基本上是一个 PDF 阅读器,我需要放置一个自定义共享按钮,我需要从 Titanium 代码传递该按钮。这个按钮视图是可见的,并且在 Classic Titanium 应用程序中运行良好,并且在我以编程方式创建按钮时也运行良好。现在唯一的问题是使用合金,我为按钮创建了一个单独的控件,现在它停止工作了。

下面我粘贴了演示代码的片段。

这是我的代码,在使用程序控制时运行良好:

App.js:

var shareBase = Ti.UI.createView({
width: 40,
height: 40,
top: 0,
left: 0,
backgroundColor: 'green'
});
var shareview = Ti.UI.createView({
backgroundImage: 'shareview.png',
width: 40,
height: 40,
});
shareBase.add(shareView);
...
...
...

// Below is the code how I am passing the view for the module
var PDF_READER = require('com.investis.docreader');
var document = PDF_READER.createPDFDocument(reportFile.nativePath.trim());
...
document.setCustomView(shareBase); // Share view is being passed
document.setTitle(report.title);
document.display();

模块中的控制器接受从 Titanium 代码传递的视图: controller.m

- (void)setCustomView: (id)args {
    TiUIViewProxy *_argVw = args;
    if (!args) {
        NSLog(@"View Proxy nil", nil);
    }

    [_pdfViewController setCustomView: _argVw.view ];  // _argVw.view gets UIView from ViewProxy
    NSLog(@"View assigned here", nil);
    NSLog([_argVw description], nil);
    NSLog([_argVw.view description], nil);
}

pdfViewController.m - The controller from where original PDF Reader is called, so I need to pass the view to this controller which loads the view into Toolbar

...
_customButton = [[UIBarButtonItem alloc] initWithCustomView: _customView]; // _customView is the view which is passed from controller.m
...
// Now display button items into toolbar
toolbarItems = [NSArray arrayWithObjects:... _customButton, fixedSpace, ..., nil];

上面的代码工作正常。但是当我将代码实现为合金控制器时,自定义视图停止从控制器加载。

App.js

var pdfshare = Alloy.createController("SocialShare", {});
...
document.setCustomView(pdfshare.getView()); // Passing custom view from the controller, other code in the file remain same
...

这是如何SocialShare创建的代码。 SocialShare.xml

<Alloy>
    <View id="container" class="container">
        <View id="shareIt" onSingletap="shareIt" platform="ios"/>
        <View id="shareIt" onSingletap="shareItAndroid" platform="android" />
    </View>
</Alloy>

SocialShare.tss

".container":{
    backgroundColor: 'yellow',
    borderWidth: 2,
    borderColor: 'black',
    right: 0,
    bottom: 0
},

".container[formFactor=tablet]":{
    height: 43,
    width: 43
},

".container[formFactor=handheld]":{
    height: 40,
    width: 40
}

SocialShare.js

var args = arguments[0] || {};
...
// Here nothing extra ordinary UI related tasks are performed. Only event handlers for shareIt

模块端的代码相同,但它仍然停止工作。如果我通过以编程方式生成的视图,那么它可以正常工作。让我知道我们是否需要以不同的方式处理 Alloy 视图。我在 Google 上进行了很多搜索并阅读了文档,但找不到任何合适的解决方案。

详细信息:- 钛 SDK:3.2.3.GA

合金:1.3.0

iPhone模拟器:7.1

让我知道是否有任何解决方案或任何补丁。

4

0 回答 0