解决Titanium Tab组件click事件在iOS中不生效的方案
2013-03-31 02:54
344 查看
问题: 以下代码,tab1的click事件在Android中生效,在iOS不生效
1: function ApplicationTabGroup(Window) {
3: var self = Ti.UI.createTabGroup();
5: //create app tabs
7:
9: title : L('home'),
11: window : win1
13: win1.containingTab = tab1;
15: var tab2 = Ti.UI.createTab({
17: icon : '/images/KS_nav_views.png',
19: });
21:
23: self.addTab(tab2);
25: tab1.addEventListener('click',function(){
27: });
29: return self;
31:
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
解决方案:
通过看Titanium附带的示例程序 Kitcken Sink , 找到了解决方案.
为TabGroup添加focus事件,然后对事件参数进行判断,来确定当前被点击的是那个tab.
1: function ApplicationTabGroup(Window) {
3: var self = Ti.UI.createTabGroup();
5: //create app tabs
7:
9: title : L('home'),
11: window : win1
13: win1.containingTab = tab1;
15: var tab2 = Ti.UI.createTab({
17: icon : '/images/KS_nav_views.png',
19: });
21:
23: self.addTab(tab2);
25: self.addEventListener('focus', function(e) {
27: var info = Titanium.API.info;
29: // 在iOS中, e.source 是 TabGroup对象,
31: var src = e.source;
33: var preTab = e.previousIndex;
35: // e.tab 是当前获得焦点的tab
37: // e.previousTab 上个tab
39:
41: if (!tab) {
43: return;
45:
47: if (!preTab) {
49: return;
51:
53: info('点击了tab1');
55: info('点击了tab2');
57: });
59: return self;
61:
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
1: function ApplicationTabGroup(Window) {
2: //create module instance
3: var self = Ti.UI.createTabGroup();
4:
5: //create app tabs
6: var win1 = new Window(L('home')), win2 = new Window(L('settings'));
7:
8: var tab1 = Ti.UI.createTab({
9: title : L('home'),
10: icon : '/images/KS_nav_ui.png',
11: window : win1
12: });
13: win1.containingTab = tab1;
14:
15: var tab2 = Ti.UI.createTab({
16: title : L('settings'),
17: icon : '/images/KS_nav_views.png',
18: window : win2
19: });
20: win2.containingTab = tab2;
21:
22: self.addTab(tab1);
23: self.addTab(tab2);
24:
25: tab1.addEventListener('click',function(){
26: //这个事件在iOS中不会被触发
27: });
28:
29: return self;
30: };
31:
32: module.exports = ApplicationTabGroup;
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
解决方案:
通过看Titanium附带的示例程序 Kitcken Sink , 找到了解决方案.
为TabGroup添加focus事件,然后对事件参数进行判断,来确定当前被点击的是那个tab.
1: function ApplicationTabGroup(Window) {
2: //create module instance
3: var self = Ti.UI.createTabGroup();
4:
5: //create app tabs
6: var win1 = new Window(L('home')), win2 = new Window(L('settings'));
7:
8: var tab1 = Ti.UI.createTab({
9: title : L('home'),
10: icon : '/images/KS_nav_ui.png',
11: window : win1
12: });
13: win1.containingTab = tab1;
14:
15: var tab2 = Ti.UI.createTab({
16: title : L('settings'),
17: icon : '/images/KS_nav_views.png',
18: window : win2
19: });
20: win2.containingTab = tab2;
21:
22: self.addTab(tab1);
23: self.addTab(tab2);
24:
25: self.addEventListener('focus', function(e) {
26:
27: var info = Titanium.API.info;
28:
29: // 在iOS中, e.source 是 TabGroup对象,
30: // 在Android中,e.source 是 Tab对象
31: var src = e.source;
32: var tab = e.tab;
33: var preTab = e.previousIndex;
34:
35: // e.tab 是当前获得焦点的tab
36: // e.index 当前获得焦点的tab的索引,首次为-1
37: // e.previousTab 上个tab
38: // e.previousIndex 上个tab的索引,首次为null
39:
40: // On iOS, the "More..." tab is actually a tab container, not a tab. When it is clicked, e.tab is undefined.
41: if (!tab) {
42: info('在iOS中点击了"More..."');
43: return;
44: }
45:
46: // 首次
47: if (!preTab) {
48: info('首次进入');
49: return;
50: }
51:
52: if (tab === tab1) {
53: info('点击了tab1');
54: } else if (tab === tab2) {
55: info('点击了tab2');
56: }
57: });
58:
59: return self;
60: };
61:
62: module.exports = ApplicationTabGroup;
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
相关文章推荐
- 解决Titanium Tab组件click事件在iOS中不生效的方案
- IOS 使用百度社会化分享组件 个别问题解决方案
- IOS设备上给body绑定click事件不生效的原因及解决办法
- ios审核 2.23 问题解决方案
- no such file or directory: 'Coding_iOS/Coding_iOS-Prefix.pch'问题解决方案
- iOS下的 Fixed + Input 调用键盘的时候fixed无效问题解决方案
- iOS开发屏幕适配问题解决方案
- iOS开发笔记之六十四——基于UIView模块化组件方案
- 详解Vue2中组件间通信的解决全方案
- [置顶] iOS 滚动视图的复用问题解决方案
- iOS全局返回按钮定制问题解决方案
- iOS开发之使用CocoaPods更新第三方出现“target overrides the `OTHER_LDFLAGS`……”问题解决方案
- 【SSH进阶之路】一步步重构容器实现Spring框架——解决容器对组件的“侵入式”管理的两种方案--主动查找和控制反转(九)
- NDK 编译时出现 algorithm,vector std::ios_base::Init::Init() , 以及ostream等问题解决方案
- Vue 动态设置网站title 解决ios在微信浏览器中不生效问题
- 用document.title=“xxx”动态修改title,在ios的微信下面不生效的解决办法!
- iOS 循环引用问题解决方案
- 解决ios微信下vue项目组件切换并自动播放音频问题
- 【iOS开发】AsyncSocket长连接粘包问题解决方案
- iOS应用发布Invalid Binary问题解决方案