Fix retain cycle in settings views.

pull/1/head
Matthew Chen 7 years ago
parent f40b81ca4c
commit 56fe3663e6

@ -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]];

@ -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];
}

Loading…
Cancel
Save