Bug Fix: App crashes while the user switches the selected tab

#1233
This commit is contained in:
Giom Foret
2017-05-19 17:22:26 +02:00
parent 84f2845c04
commit 4e48cfa86c
5 changed files with 51 additions and 6 deletions
+35 -6
View File
@@ -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