解决Titanium Tab组件click事件在iOS中不生效的方案
2013-03-31 02:54
267 查看
问题: 以下代码,tab1的click事件在Android中生效,在iOS不生效
[/code]
.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.
[/code]
.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; }
function ApplicationTabGroup(Window) {
[code] //create module instance
var self = Ti.UI.createTabGroup();
//create app tabs
var win1 = new Window(L('home')), win2 = new Window(L('settings'));
var tab1 = Ti.UI.createTab({
title : L('home'),
icon : '/images/KS_nav_ui.png',
window : win1
});
win1.containingTab = tab1;
var tab2 = Ti.UI.createTab({
title : L('settings'),
icon : '/images/KS_nav_views.png',
window : win2
});
win2.containingTab = tab2;
self.addTab(tab1);
self.addTab(tab2);
tab1.addEventListener('click',function(){
//这个事件在iOS中不会被触发
});
return self;
};
module.exports = ApplicationTabGroup;
[/code]
.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.
function ApplicationTabGroup(Window) {
[code] //create module instance
var self = Ti.UI.createTabGroup();
//create app tabs
var win1 = new Window(L('home')), win2 = new Window(L('settings'));
var tab1 = Ti.UI.createTab({
title : L('home'),
icon : '/images/KS_nav_ui.png',
window : win1
});
win1.containingTab = tab1;
var tab2 = Ti.UI.createTab({
title : L('settings'),
icon : '/images/KS_nav_views.png',
window : win2
});
win2.containingTab = tab2;
self.addTab(tab1);
self.addTab(tab2);
self.addEventListener('focus', function(e) {
var info = Titanium.API.info;
// 在iOS中, e.source 是 TabGroup对象,
// 在Android中,e.source 是 Tab对象
var src = e.source;
var tab = e.tab;
var preTab = e.previousIndex;
// e.tab 是当前获得焦点的tab
// e.index 当前获得焦点的tab的索引,首次为-1
// e.previousTab 上个tab
// e.previousIndex 上个tab的索引,首次为null
// On iOS, the "More..." tab is actually a tab container, not a tab. When it is clicked, e.tab is undefined.
if (!tab) {
info('在iOS中点击了"More..."');
return;
}
// 首次
if (!preTab) {
info('首次进入');
return;
}
if (tab === tab1) {
info('点击了tab1');
} else if (tab === tab2) {
info('点击了tab2');
}
});
return self;
};
module.exports = ApplicationTabGroup;
[/code]
.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问题解决方案