diff --git a/iphone/Classes/TiUIListView.m b/iphone/Classes/TiUIListView.m index f893e7a4255..3aac24b5fb5 100644 --- a/iphone/Classes/TiUIListView.m +++ b/iphone/Classes/TiUIListView.m @@ -1169,30 +1169,7 @@ - (void)tableView:(UITableView *)tableView didBeginMultipleSelectionInteractionA - (void)tableViewDidEndMultipleSelectionInteraction:(UITableView *)tableView { - if ([self.proxy _hasListeners:@"itemsselected"]) { - NSMutableArray *selectedItems = [NSMutableArray arrayWithCapacity:tableView.indexPathsForSelectedRows.count]; - NSMutableDictionary *startingItem = [NSMutableDictionary dictionaryWithCapacity:1]; - - for (int i = 0; i < tableView.indexPathsForSelectedRows.count; i++) { - NSIndexPath *indexPath = tableView.indexPathsForSelectedRows[i]; - NSIndexPath *realIndexPath = [self pathForSearchPath:indexPath]; - TiUIListSectionProxy *theSection = [[self.listViewProxy sectionForIndex:realIndexPath.section] retain]; - - NSMutableDictionary *eventObject = [[NSMutableDictionary alloc] initWithObjectsAndKeys: - theSection, @"section", - NUMINTEGER(realIndexPath.section), @"sectionIndex", - NUMINTEGER(realIndexPath.row), @"itemIndex", - nil]; - if (i == 0) { - [startingItem setDictionary:eventObject]; - } - [selectedItems addObject:eventObject]; - - RELEASE_TO_NIL(eventObject); - RELEASE_TO_NIL(theSection); - } - [self.proxy fireEvent:@"itemsselected" withObject:@{ @"selectedItems" : selectedItems, @"startingItem" : startingItem }]; - } + [self fireItemsSelectedEvent]; } - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath @@ -1891,6 +1868,12 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath { // send indexPath of tableView which could be self.tableView or searchController.searchResultsTableView [self fireClickForItemAtIndexPath:indexPath tableView:tableView accessoryButtonTapped:NO]; + [self fireItemsSelectedEvent]; +} + +- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath +{ + [self fireItemsSelectedEvent]; } - (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath @@ -2333,6 +2316,34 @@ - (void)fireClickForItemAtIndexPath:(NSIndexPath *)indexPath tableView:(UITableV [eventObject release]; } +- (void)fireItemsSelectedEvent +{ + if ((_tableView != nil) && [self.proxy _hasListeners:@"itemsselected"]) { + NSMutableArray *selectedItems = [NSMutableArray arrayWithCapacity:_tableView.indexPathsForSelectedRows.count]; + NSMutableDictionary *startingItem = [NSMutableDictionary dictionaryWithCapacity:1]; + + for (int i = 0; i < _tableView.indexPathsForSelectedRows.count; i++) { + NSIndexPath *indexPath = _tableView.indexPathsForSelectedRows[i]; + NSIndexPath *realIndexPath = [self pathForSearchPath:indexPath]; + TiUIListSectionProxy *theSection = [[self.listViewProxy sectionForIndex:realIndexPath.section] retain]; + + NSMutableDictionary *eventObject = [[NSMutableDictionary alloc] initWithObjectsAndKeys: + theSection, @"section", + NUMINTEGER(realIndexPath.section), @"sectionIndex", + NUMINTEGER(realIndexPath.row), @"itemIndex", + nil]; + if (i == 0) { + [startingItem setDictionary:eventObject]; + } + [selectedItems addObject:eventObject]; + + RELEASE_TO_NIL(eventObject); + RELEASE_TO_NIL(theSection); + } + [self.proxy fireEvent:@"itemsselected" withObject:@{ @"selectedItems" : selectedItems, @"startingItem" : startingItem }]; + } +} + - (CGFloat)contentWidthForWidth:(CGFloat)width { return width; diff --git a/iphone/Classes/TiUITableView.m b/iphone/Classes/TiUITableView.m index c2dc5ffd844..85a0ba48278 100644 --- a/iphone/Classes/TiUITableView.m +++ b/iphone/Classes/TiUITableView.m @@ -2321,30 +2321,7 @@ - (void)tableView:(UITableView *)tableView didBeginMultipleSelectionInteractionA - (void)tableViewDidEndMultipleSelectionInteraction:(UITableView *)tableView { - if ([self.proxy _hasListeners:@"rowsselected"]) { - NSMutableArray *selectedItems = [NSMutableArray arrayWithCapacity:tableView.indexPathsForSelectedRows.count]; - NSMutableDictionary *startingRowObject = [NSMutableDictionary dictionaryWithCapacity:1]; - - for (int i = 0; i < tableView.indexPathsForSelectedRows.count; i++) { - NSIndexPath *index = tableView.indexPathsForSelectedRows[i]; - NSInteger sectionIdx = [index section]; - NSArray *sections = [(TiUITableViewProxy *)[self proxy] internalSections]; - TiUITableViewSectionProxy *section = [self sectionForIndex:sectionIdx]; - - NSInteger dataIndex = [self rowIndexForIndexPath:index andSections:sections]; - - TiUITableViewRowProxy *row = [section rowAtIndex:[index row]]; - - NSMutableDictionary *eventObject = [NSMutableDictionary dictionaryWithObjectsAndKeys: - section, @"section", - NUMINTEGER(dataIndex), @"index", - row, @"row", - row, @"rowData", - nil]; - [selectedItems addObject:eventObject]; - } - [self.proxy fireEvent:@"rowsselected" withObject:@{ @"selectedRows" : selectedItems, @"startingRow" : startingRowObject }]; - } + [self fireRowsSelectedEvent]; } #pragma mark Collation @@ -2514,6 +2491,12 @@ - (void)tableView:(UITableView *)ourTableView didSelectRowAtIndexPath:(NSIndexPa search = YES; } [self triggerActionForIndexPath:indexPath fromPath:nil tableView:ourTableView wasAccessory:NO search:search name:@"click"]; + [self fireRowsSelectedEvent]; +} + +- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath +{ + [self fireRowsSelectedEvent]; } - (void)tableView:(UITableView *)ourTableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath @@ -2781,6 +2764,45 @@ - (void)fireScrollEvent:(UIScrollView *)scrollView } } +- (void)fireRowsSelectedEvent +{ + // Do not continue if TableView has been released. + if (!tableview) { + return; + } + + // Do not continue if not in multi-selection edit mode. + if (!tableview.editing || !tableview.allowsMultipleSelectionDuringEditing) { + return; + } + + // Do not continue if there aren't any listeners. + NSString *eventName = @"rowsselected"; + if (![self.proxy _hasListeners:eventName]) { + return; + } + + // Fire an event providing an array of all selected rows. + NSMutableArray *selectedItems = [NSMutableArray arrayWithCapacity:tableview.indexPathsForSelectedRows.count]; + NSMutableDictionary *startingRowObject = [NSMutableDictionary dictionaryWithCapacity:1]; + for (int i = 0; i < tableview.indexPathsForSelectedRows.count; i++) { + NSIndexPath *index = tableview.indexPathsForSelectedRows[i]; + NSInteger sectionIdx = [index section]; + NSArray *sections = [(TiUITableViewProxy *)[self proxy] internalSections]; + TiUITableViewSectionProxy *section = [self sectionForIndex:sectionIdx]; + NSInteger dataIndex = [self rowIndexForIndexPath:index andSections:sections]; + TiUITableViewRowProxy *row = [section rowAtIndex:[index row]]; + NSMutableDictionary *eventObject = [NSMutableDictionary dictionaryWithObjectsAndKeys: + section, @"section", + NUMINTEGER(dataIndex), @"index", + row, @"row", + row, @"rowData", + nil]; + [selectedItems addObject:eventObject]; + } + [self.proxy fireEvent:eventName withObject:@{ @"selectedRows" : selectedItems, @"startingRow" : startingRowObject }]; +} + - (void)scrollViewDidScroll:(UIScrollView *)scrollView { if (scrollView.isDragging || scrollView.isDecelerating) {