From 56fe3663e6b1f5b4755d9e7fa7bad099fd35032f Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 21 Nov 2018 14:21:10 -0800 Subject: [PATCH] Fix retain cycle in settings views. --- .../AppSettings/AppSettingsViewController.m | 9 +++++--- .../ViewControllers/ProfileViewController.m | 22 ++++++++++++------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/Signal/src/ViewControllers/AppSettings/AppSettingsViewController.m b/Signal/src/ViewControllers/AppSettings/AppSettingsViewController.m index d376dd3de..22f1e2944 100644 --- a/Signal/src/ViewControllers/AppSettings/AppSettingsViewController.m +++ b/Signal/src/ViewControllers/AppSettings/AppSettingsViewController.m @@ -248,7 +248,8 @@ - (OWSTableItem *)destructiveButtonItemWithTitle:(NSString *)title selector:(SEL)selector color:(UIColor *)color { - return [OWSTableItem + __weak AppSettingsViewController *weakSelf = self; + return [OWSTableItem itemWithCustomCellBlock:^{ UITableViewCell *cell = [OWSTableItem newCell]; cell.preservesSuperviewLayoutMargins = YES; @@ -260,7 +261,7 @@ font:[OWSFlatButton fontForHeight:kButtonHeight] titleColor:[UIColor whiteColor] backgroundColor:color - target:self + target:weakSelf selector:selector]; [cell.contentView addSubview:button]; [button autoSetDimension:ALDimensionHeight toSize:kButtonHeight]; @@ -423,6 +424,8 @@ - (void)showDeleteAccountUI:(BOOL)isRegistered { + __weak AppSettingsViewController *weakSelf = self; + UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"CONFIRM_ACCOUNT_DESTRUCTION_TITLE", @"") message:NSLocalizedString(@"CONFIRM_ACCOUNT_DESTRUCTION_TEXT", @"") @@ -430,7 +433,7 @@ [alertController addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"PROCEED_BUTTON", @"") style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) { - [self deleteAccount:isRegistered]; + [weakSelf deleteAccount:isRegistered]; }]]; [alertController addAction:[OWSAlerts cancelAction]]; diff --git a/Signal/src/ViewControllers/ProfileViewController.m b/Signal/src/ViewControllers/ProfileViewController.m index c0dfaef0a..3033236d3 100644 --- a/Signal/src/ViewControllers/ProfileViewController.m +++ b/Signal/src/ViewControllers/ProfileViewController.m @@ -287,7 +287,8 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat [self profileCompletedOrSkipped]; return; } - + + __weak ProfileViewController *weakSelf = self; UIAlertController *controller = [UIAlertController alertControllerWithTitle: NSLocalizedString(@"NEW_GROUP_VIEW_UNSAVED_CHANGES_TITLE", @@ -301,7 +302,7 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat @"The label for the 'discard' button in alerts and action sheets.") style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) { - [self profileCompletedOrSkipped]; + [weakSelf profileCompletedOrSkipped]; }]]; [controller addAction:[OWSAlerts cancelAction]]; [self presentViewController:controller animated:YES completion:nil]; @@ -388,7 +389,7 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat canCancel:NO backgroundBlock:^(ModalActivityIndicatorViewController *modalActivityIndicator) { [OWSProfileManager.sharedManager updateLocalProfileName:normalizedProfileName - avatarImage:self.avatar + avatarImage:weakSelf.avatar success:^{ dispatch_async(dispatch_get_main_queue(), ^{ [modalActivityIndicator dismissWithCompletion:^{ @@ -425,6 +426,9 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat { OWSLogVerbose(@""); + [self checkCanImportBackup]; + return; + // Dismiss this view. switch (self.profileViewMode) { case ProfileViewMode_AppSettings: @@ -467,6 +471,7 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat { OWSLogVerbose(@""); + __weak ProfileViewController *weakSelf = self; [OWSBackup.sharedManager checkCanImportBackup:^(BOOL value) { OWSLogInfo(@"has backup available for import? %d", value); @@ -474,13 +479,13 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat if (value) { [OWSBackup.sharedManager setHasPendingRestoreDecision:YES]; - [self showBackupRestoreView]; + [weakSelf showBackupRestoreView]; } else { - [self showHomeView]; + [weakSelf showHomeView]; } } failure:^(NSError *error) { - [self showBackupCheckFailedAlert]; + [weakSelf showBackupCheckFailedAlert]; }]; } @@ -488,6 +493,7 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat { OWSLogVerbose(@""); + __weak ProfileViewController *weakSelf = self; UIAlertController *controller = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"CHECK_FOR_BACKUP_FAILED_TITLE", @"Title for alert shown when the app failed to check for an existing backup.") @@ -498,13 +504,13 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat [controller addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"REGISTER_FAILED_TRY_AGAIN", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { - [self checkCanImportBackup]; + [weakSelf checkCanImportBackup]; }]]; [controller addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"CHECK_FOR_BACKUP_DO_NOT_RESTORE", @"The label for the 'do not restore backup' button.") style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) { - [self showHomeView]; + [weakSelf showHomeView]; }]]; [self presentViewController:controller animated:YES completion:nil]; }