[TIMOB-5066] Toolbar button click events not always firing
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2011-09-30T16:40:42.000+0000 |
Affected Version/s | Release 1.7.0, Release 1.7.1, Release 1.7.2 |
Fix Version/s | Sprint 2011-37, Release 1.8.0 |
Components | iOS |
Labels | module_toolbar, qe-testadded |
Reporter | Matthew Apperson |
Assignee | Blain Hamon |
Created | 2011-08-22T09:48:02.000+0000 |
Updated | 2014-06-19T12:46:39.000+0000 |
Description
When win is defined outside of the apps namespace, the click event is fired twice TOTAL for the toolbar, so 2 on the same button or one time on two different buttons.
var win = Ti.UI.createWindow();
var app = {};
app.createToolbar = function() {
var b1 = Ti.UI.createButton({
title: "b1",
left: 5
});
var b2 = Ti.UI.createButton({
title: "b2",
right: 5
});
b1.addEventListener('click', function() {
alert("button 1 called.");
});
b2.addEventListener('click', function() {
alert("button 2 called");
});
var toolbar = Titanium.UI.createToolbar({
items:[b1, b2]
});
win.add(toolbar);
}
app.createToolbar();
win.open();
iOS SDK 4.3. My sample view (with some code removed). Buttons fire once or twice and then not again, doesn't matter which button you press first and second. Any of them will first at least once.
I am having the same issue, Have you guys had a time to work on this yet, can I know what exactly is causing this problem.
The same here, my case is exposed in this Q&A, with a workaround from Goran Skledar http://developer.appcelerator.com/question/125494/inexplicable-bug-toolbar-button-only-listens-4-clicks
This bug does not happen when all elements are created in the global scope. For example, create an app with this in app.js and you will find the click event fires every time:
However, if you wrap the same code in a closure, then you encounter this bug.
Closing bug. Verified fix using Modulization Toolbar test case on: OS: Mac OS X Lion Titanium Studio, build: 1.0.7.201112080131 SDK build: 1.8.0.1.v20111207180431 Devices: iphone 4S Sprint (5.0.1)
I'm still seeing this issue with similar code compiled with a recent SDK build: Titanium Studio, build: 1.0.8.201112161851 [INFO] Titanium SDK version: 1.8.0.1 (12/15/11 16:31 c44f563) iOS 5.0.1 SDK simulator and iPhone 4S.
Here's a simple app.js that reproduces the problem on the latest SDK. The toolbar button created in global scope works consistently; the toolbar button created in a closure stops responding to clicks after four events.
Workaround is to hang on to a reference to the toolbar button in the text field, like so: