Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-7030] iOS: TableView - click event contains incorrect data when searchbar filter active

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2012-04-02T20:14:29.000+0000
Affected Version/sRelease 1.6.0
Fix Version/sRelease 2.0.0, Sprint 2012-06
ComponentsiOS
Labelsmodule_tableview, qe-testadded
ReporterJames David Low
AssigneeBlain Hamon
Created2011-12-07T06:25:34.000+0000
Updated2012-11-07T18:33:43.000+0000

Description

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

Attachments

FileDateSize
build.log2012-01-08T15:51:27.000+00001068547
TableTest.zip2012-01-08T15:39:27.000+00002319864
TiUITableView.m2012-01-08T15:51:27.000+000066407

Comments

  1. James David Low 2011-12-07

    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
  2. James David Low 2011-12-07

    I'm also actually a paying titanium member, but jira wouldn't let me raised this against the TIMOB project directly.
  3. Paul Dowsett 2011-12-28

    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
  4. James David Low 2012-01-08

    Hi, I've updated with the requested info. Thanks, James
  5. Paul Dowsett 2012-01-08

    Thank you very much for this, James, I'm moving it across.
  6. Paul Dowsett 2012-01-08

    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
  7. James David Low 2012-01-08

    Hi Paul, Updated with the relevant information. It has basically affected all version of Titanium/iOS since I've started using it.
  8. Paul Dowsett 2012-01-09

    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
  9. James David Low 2012-01-09

    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.
  10. James David Low 2012-01-09

    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.
  11. Stephen Tramer 2012-03-12

    Assigning to Blain, as he is in charge of processing the pull request.
  12. Blain Hamon 2012-03-12

    Community pull #866 processed. Credit to James Low.
  13. Wilson Luu 2012-03-15

    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)
  14. Michael Pettiford 2012-04-02

    Reopening/closing to add/remove labels

JSON Source