diff --git a/Riot/Model/RoomList/RecentsDataSource.m b/Riot/Model/RoomList/RecentsDataSource.m index bb3772829..4a347b0af 100644 --- a/Riot/Model/RoomList/RecentsDataSource.m +++ b/Riot/Model/RoomList/RecentsDataSource.m @@ -227,6 +227,13 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { + // Sanity check + if (tableView.tag != self.recentsDataSourceMode) + { + // The view controller of this table view is not the current selected one in the tab bar controller. + return 0; + } + NSInteger sectionsCount = 0; // Check whether all data sources are ready before rendering recents @@ -272,6 +279,13 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + // Sanity check + if (tableView.tag != self.recentsDataSourceMode) + { + // The view controller of this table view is not the current selected one in the tab bar controller. + return 0; + } + NSUInteger count = 0; if (section == favoritesSection && !(shrinkedSectionsBitMask & RECENTSDATASOURCE_SECTION_FAVORITES)) @@ -660,6 +674,14 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + // Sanity check + if (tableView.tag != self.recentsDataSourceMode) + { + // The view controller of this table view is not the current selected one in the tab bar controller. + // Return a fake cell to prevent app from crashing + return [[UITableViewCell alloc] init]; + } + if (indexPath.section == directorySection) { NSIndexPath *indexPathInPublicRooms = [NSIndexPath indexPathForRow:indexPath.row inSection:0]; @@ -808,6 +830,19 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou return 0; } +- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath +{ + // Sanity check + if (tableView.tag != self.recentsDataSourceMode) + { + // The view controller of this table view is not the current selected one in the tab bar controller. + return NO; + } + + // Invited rooms are not editable. + return (indexPath.section != invitesSection); +} + #pragma mark - - (NSInteger)cellIndexPosWithRoomId:(NSString*)roomId andMatrixSession:(MXSession*)matrixSession within:(NSMutableArray*)cellDataArray @@ -1192,12 +1227,6 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou } } -- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath -{ - // Invited rooms are not editable. - return (indexPath.section != invitesSection); -} - #pragma mark - drag and drop managemenent - (BOOL)isDraggableCellAt:(NSIndexPath*)path diff --git a/Riot/ViewController/FavouritesViewController.m b/Riot/ViewController/FavouritesViewController.m index 44adc3ff1..176e5e895 100644 --- a/Riot/ViewController/FavouritesViewController.m +++ b/Riot/ViewController/FavouritesViewController.m @@ -37,6 +37,10 @@ self.view.accessibilityIdentifier = @"FavouritesVCView"; self.recentsTableView.accessibilityIdentifier = @"FavouritesVCTableView"; + + // Tag the recents table with the its recents data source mode. + // This will be used by the shared RecentsDataSource instance for sanity checks (see UITableViewDataSource methods). + self.recentsTableView.tag = RecentsDataSourceModeFavourites; } - (void)viewWillAppear:(BOOL)animated diff --git a/Riot/ViewController/HomeViewController.m b/Riot/ViewController/HomeViewController.m index 85f37c0fd..a9acfb47d 100644 --- a/Riot/ViewController/HomeViewController.m +++ b/Riot/ViewController/HomeViewController.m @@ -46,6 +46,10 @@ self.view.accessibilityIdentifier = @"HomeVCView"; self.recentsTableView.accessibilityIdentifier = @"HomeVCTableView"; + // Tag the recents table with the its recents data source mode. + // This will be used by the shared RecentsDataSource instance for sanity checks (see UITableViewDataSource methods). + self.recentsTableView.tag = RecentsDataSourceModeHome; + // Add the (+) button programmatically [self addPlusButton]; diff --git a/Riot/ViewController/PeopleViewController.m b/Riot/ViewController/PeopleViewController.m index 1e23f9197..4c54f9a89 100644 --- a/Riot/ViewController/PeopleViewController.m +++ b/Riot/ViewController/PeopleViewController.m @@ -63,6 +63,10 @@ self.view.accessibilityIdentifier = @"PeopleVCView"; self.recentsTableView.accessibilityIdentifier = @"PeopleVCTableView"; + // Tag the recents table with the its recents data source mode. + // This will be used by the shared RecentsDataSource instance for sanity checks (see UITableViewDataSource methods). + self.recentsTableView.tag = RecentsDataSourceModePeople; + // Add the (+) button programmatically [self addPlusButton]; diff --git a/Riot/ViewController/RoomsViewController.m b/Riot/ViewController/RoomsViewController.m index a062d41a0..cc0b27f0c 100644 --- a/Riot/ViewController/RoomsViewController.m +++ b/Riot/ViewController/RoomsViewController.m @@ -47,6 +47,10 @@ self.view.accessibilityIdentifier = @"RoomsVCView"; self.recentsTableView.accessibilityIdentifier = @"RoomsVCTableView"; + // Tag the recents table with the its recents data source mode. + // This will be used by the shared RecentsDataSource instance for sanity checks (see UITableViewDataSource methods). + self.recentsTableView.tag = RecentsDataSourceModeRooms; + // Add the (+) button programmatically [self addPlusButton];