Problem
TableView click event has wrong data when you are current running a seach and then click the detail button. If you do a search in TableView and click the detail button of the first search result it will give you the rowData from the first row when there is no search. If you tap the row itself it gives you the correct data. I have tracked this down to TiUITableView.m (see patch below).
Test Case
TableTest.zip:
Included a full demo app that shows the problem in action. Instructions for running:
Run in iPhone simulator
Click a table row detail button to show it by default shows the correct values
Type "third" in the search bar for the table view
Click the table row detail button to show that when searching it shows the wrong data when searching
var tabGroup = Ti.UI.createTabGroup();
var win = Ti.UI.createWindow({});
var tab = Ti.UI.createTab({
title: 'Table Test',
window: win
});
var data = [
{title: 'First Row', hasDetail: true},
{title: 'Second Row', hasDetail: true},
{title: 'Third Row', hasDetail: true},
{title: 'Forth Row', hasDetail: true},
{title: 'Fifth Row', hasDetail: true}
];
var search = Ti.UI.createSearchBar({
returnKeyType: Ti.UI.RETURNKEY_DONE
});
var tableView = Ti.UI.createTableView({
data: data,
search: search
});
tableView.addEventListener('click', function (e) {
alert('Click Event. index: ' + e.index + ', Title: ' + e.row.title);
});
win.add(tableView);
tabGroup.addTab(tab);
tabGroup.open();
Solution
- (void)tableView:(UITableView *)ourTableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
BOOL search = NO;
if (allowsSelectionSet==NO || [ourTableView allowsSelection]==NO)
{
[ourTableView deselectRowAtIndexPath:indexPath animated:YES];
}
if(ourTableView != tableview)
{
search = YES;
}
[self triggerActionForIndexPath:indexPath fromPath:nil tableView:ourTableView wasAccessory:YES search:search name:@"click"];
}
Logs
See attached build log
When you click accessory buttons when you're running a search on a table view, the wrong row data is passed to the click event. This is because unlike the main click delegate (didSelectRowAtIndexPath) it does not take into account that a search is currently being run. This has been around since at least 1.4.0 or so, maybe even earlier. I keep changing my local code in ever new version of Titanium that is released. Its a few line fix so would be really good if it was fixed in the Titanium master code. I've filled in a pull request here: https://github.com/appcelerator/titanium_mobile/pull/866 I also filled in the form for contributing to the Titanium project quite a while a go with my github id jamesdlow
I'm also actually a paying titanium member, but jira wouldn't let me raised this against the TIMOB project directly.
James Thanks for raising this ticket, and for your efforts in creating a patch. In order for me to escalate it to the core team, however, and also accept the Pull Request, all the fields in this ticket must be complete. Please check it against the [JIRA Ticket Checklist](https://wiki.appcelerator.org/display/guides/How+to+Submit+a+Bug+Report#HowtoSubmitaBugReport-JIRATicketChecklist), and add any missing information. Furthermore, a simple test case must be included and run without modification, as per the [Creating a Test Case](https://wiki.appcelerator.org/display/guides/How+to+Submit+a+Bug+Report#HowtoSubmitaBugReport-CreatingaTestCase) section. I will mark this resolved for now. Please reopen it once it is complete, and I will move it to the main project. Cheers
Hi, I've updated with the requested info. Thanks, James
Thank you very much for this, James, I'm moving it across.
Apologies, would you complete the environment field, and then I will definitely be able to move it! ;) Most importantly, what version of ios have you seen this issue with, and have you tested in the simulator, and/or seen it on a device? Thanks
Hi Paul, Updated with the relevant information. It has basically affected all version of Titanium/iOS since I've started using it.
Thanks, James. I will move it over but, for completeness, I was hoping for the device that you have tested it on. If that's just the simulator, would you state that? Thanks
Oh its not just the simulator. On my app that I've implemented a fix for its run the most on iOS 4.3 and 5.0 and mainly using Titanium 1.7.3, but I've been manually updating TiUITableView.m with this fix every time a new SDK is released at least since 1.6.0.
Oh its not just the simulator. On my app that I've implemented a fix for its run the most on iOS 4.3 and 5.0 and mainly using Titanium 1.7.3, but I've been manually updating TiUITableView.m with this fix every time a new SDK is released at least since 1.6.0.
Assigning to Blain, as he is in charge of processing the pull request.
Community pull #866 processed. Credit to James Low.
Closing bug. Verified fix on: SDK build: 2.0.0.v20120315123246 Titanium Studio, build: 2.0.0.201203142055 xcode: 4.2 Device: iphone 4s (5.0.1)
Reopening/closing to add/remove labels