Fix a visual bug that would sometimes occur while rendering settings switches. Thanks to Gunnar C. Pope for the bug report.

pull/2/head
Matthew Chen 6 years ago committed by Michael Kirk
parent c15084c6f4
commit 72082edad8

@ -89,7 +89,9 @@ NS_ASSUME_NONNULL_BEGIN
OWSTableSection *loggingSection = [OWSTableSection new]; OWSTableSection *loggingSection = [OWSTableSection new];
loggingSection.headerTitle = NSLocalizedString(@"LOGGING_SECTION", nil); loggingSection.headerTitle = NSLocalizedString(@"LOGGING_SECTION", nil);
[loggingSection addItem:[OWSTableItem switchItemWithText:NSLocalizedString(@"SETTINGS_ADVANCED_DEBUGLOG", @"") [loggingSection addItem:[OWSTableItem switchItemWithText:NSLocalizedString(@"SETTINGS_ADVANCED_DEBUGLOG", @"")
isOn:[OWSPreferences isLoggingEnabled] isOnBlock:^{
return [OWSPreferences isLoggingEnabled];
}
target:weakSelf target:weakSelf
selector:@selector(didToggleEnableLogSwitch:)]]; selector:@selector(didToggleEnableLogSwitch:)]];
@ -160,21 +162,26 @@ NS_ASSUME_NONNULL_BEGIN
// * ...The internet is not reachable, since we don't want to let users to activate // * ...The internet is not reachable, since we don't want to let users to activate
// censorship circumvention unnecessarily, e.g. if they just don't have a valid // censorship circumvention unnecessarily, e.g. if they just don't have a valid
// internet connection. // internet connection.
BOOL isManualCensorshipCircumventionOnEnabled OWSTableSwitchBlock isCensorshipCircumventionOnBlock = ^{
= (OWSSignalService.sharedInstance.isCensorshipCircumventionManuallyActivated
|| (!OWSSignalService.sharedInstance.hasCensoredPhoneNumber && !isAnySocketOpen
&& weakSelf.reachability.isReachable));
BOOL isCensorshipCircumventionOn = NO;
if (OWSSignalService.sharedInstance.hasCensoredPhoneNumber) { if (OWSSignalService.sharedInstance.hasCensoredPhoneNumber) {
isCensorshipCircumventionOn = YES; return YES;
} else { } else {
isCensorshipCircumventionOn = OWSSignalService.sharedInstance.isCensorshipCircumventionManuallyActivated; return OWSSignalService.sharedInstance.isCensorshipCircumventionManuallyActivated;
} }
};
Reachability *reachability = self.reachability;
OWSTableSwitchBlock isManualCensorshipCircumventionOnEnabledBlock = ^{
BOOL isAnySocketOpen = TSSocketManager.shared.highestSocketState == OWSWebSocketStateOpen;
BOOL value = (OWSSignalService.sharedInstance.isCensorshipCircumventionManuallyActivated
|| (!OWSSignalService.sharedInstance.hasCensoredPhoneNumber && !isAnySocketOpen
&& reachability.isReachable));
return value;
};
[censorshipSection [censorshipSection
addItem:[OWSTableItem switchItemWithText:NSLocalizedString(@"SETTINGS_ADVANCED_CENSORSHIP_CIRCUMVENTION", addItem:[OWSTableItem switchItemWithText:NSLocalizedString(@"SETTINGS_ADVANCED_CENSORSHIP_CIRCUMVENTION",
@"Label for the 'manual censorship circumvention' switch.") @"Label for the 'manual censorship circumvention' switch.")
isOn:isCensorshipCircumventionOn isOnBlock:isCensorshipCircumventionOnBlock
isEnabled:isManualCensorshipCircumventionOnEnabled isEnabledBlock:isManualCensorshipCircumventionOnEnabledBlock
target:weakSelf target:weakSelf
selector:@selector(didToggleEnableCensorshipCircumventionSwitch:)]]; selector:@selector(didToggleEnableCensorshipCircumventionSwitch:)]];

@ -1,5 +1,5 @@
// //
// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // Copyright (c) 2019 Open Whisper Systems. All rights reserved.
// //
#import "BlockListViewController.h" #import "BlockListViewController.h"
@ -91,8 +91,7 @@ NS_ASSUME_NONNULL_BEGIN
@"BLOCK_LIST_BLOCKED_USERS_SECTION", @"Section header for users that have been blocked"); @"BLOCK_LIST_BLOCKED_USERS_SECTION", @"Section header for users that have been blocked");
for (NSString *phoneNumber in blockedPhoneNumbers) { for (NSString *phoneNumber in blockedPhoneNumbers) {
[blockedContactsSection [blockedContactsSection addItem:[OWSTableItem
addItem:[OWSTableItem
itemWithCustomCellBlock:^{ itemWithCustomCellBlock:^{
ContactTableViewCell *cell = [ContactTableViewCell new]; ContactTableViewCell *cell = [ContactTableViewCell new];
[cell configureWithRecipientId:phoneNumber]; [cell configureWithRecipientId:phoneNumber];
@ -100,11 +99,14 @@ NS_ASSUME_NONNULL_BEGIN
} }
customRowHeight:UITableViewAutomaticDimension customRowHeight:UITableViewAutomaticDimension
actionBlock:^{ actionBlock:^{
[BlockListUIUtils showUnblockPhoneNumberActionSheet:phoneNumber [BlockListUIUtils
showUnblockPhoneNumberActionSheet:phoneNumber
fromViewController:weakSelf fromViewController:weakSelf
blockingManager:helper.blockingManager blockingManager:helper.blockingManager
contactsManager:helper.contactsManager contactsManager:helper.contactsManager
completionBlock:nil]; completionBlock:^(BOOL isBlocked) {
[weakSelf updateTableContents];
}];
}]]; }]];
} }
[contents addSection:blockedContactsSection]; [contents addSection:blockedContactsSection];
@ -142,7 +144,9 @@ NS_ASSUME_NONNULL_BEGIN
displayName:groupName displayName:groupName
fromViewController:weakSelf fromViewController:weakSelf
blockingManager:helper.blockingManager blockingManager:helper.blockingManager
completionBlock:nil]; completionBlock:^(BOOL isBlocked) {
[weakSelf updateTableContents];
}];
}]]; }]];
} }
[contents addSection:blockedGroupsSection]; [contents addSection:blockedGroupsSection];

@ -1,5 +1,5 @@
// //
// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // Copyright (c) 2019 Open Whisper Systems. All rights reserved.
// //
#import "NotificationSettingsViewController.h" #import "NotificationSettingsViewController.h"
@ -56,7 +56,9 @@
@"Table cell switch label. When disabled, Signal will not play notification sounds while the app is in the " @"Table cell switch label. When disabled, Signal will not play notification sounds while the app is in the "
@"foreground."); @"foreground.");
[soundsSection addItem:[OWSTableItem switchItemWithText:inAppSoundsLabelText [soundsSection addItem:[OWSTableItem switchItemWithText:inAppSoundsLabelText
isOn:[prefs soundInForeground] isOnBlock:^{
return [prefs soundInForeground];
}
target:weakSelf target:weakSelf
selector:@selector(didToggleSoundNotificationsSwitch:)]]; selector:@selector(didToggleSoundNotificationsSwitch:)]];
[contents addSection:soundsSection]; [contents addSection:soundsSection];

@ -1,5 +1,5 @@
// //
// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // Copyright (c) 2019 Open Whisper Systems. All rights reserved.
// //
#import "OWSBackupSettingsViewController.h" #import "OWSBackupSettingsViewController.h"
@ -117,7 +117,9 @@ NS_ASSUME_NONNULL_BEGIN
addItem:[OWSTableItem switchItemWithText: addItem:[OWSTableItem switchItemWithText:
NSLocalizedString(@"SETTINGS_BACKUP_ENABLING_SWITCH", NSLocalizedString(@"SETTINGS_BACKUP_ENABLING_SWITCH",
@"Label for switch in settings that controls whether or not backup is enabled.") @"Label for switch in settings that controls whether or not backup is enabled.")
isOn:isBackupEnabled isOnBlock:^{
return [OWSBackup.sharedManager isBackupEnabled];
}
target:self target:self
selector:@selector(isBackupEnabledDidChange:)]]; selector:@selector(isBackupEnabledDidChange:)]];
[contents addSection:enableSection]; [contents addSection:enableSection];
@ -187,6 +189,8 @@ NS_ASSUME_NONNULL_BEGIN
- (void)isBackupEnabledDidChange:(UISwitch *)sender - (void)isBackupEnabledDidChange:(UISwitch *)sender
{ {
[OWSBackup.sharedManager setIsBackupEnabled:sender.isOn]; [OWSBackup.sharedManager setIsBackupEnabled:sender.isOn];
[self updateTableContents];
} }
#pragma mark - Events #pragma mark - Events

@ -98,9 +98,12 @@ static NSString *const kSealedSenderInfoURL = @"https://signal.org/blog/sealed-s
= NSLocalizedString(@"SETTINGS_READ_RECEIPT", @"Label for the 'read receipts' setting."); = NSLocalizedString(@"SETTINGS_READ_RECEIPT", @"Label for the 'read receipts' setting.");
readReceiptsSection.footerTitle = NSLocalizedString( readReceiptsSection.footerTitle = NSLocalizedString(
@"SETTINGS_READ_RECEIPTS_SECTION_FOOTER", @"An explanation of the 'read receipts' setting."); @"SETTINGS_READ_RECEIPTS_SECTION_FOOTER", @"An explanation of the 'read receipts' setting.");
[readReceiptsSection addItem:[OWSTableItem switchItemWithText:NSLocalizedString(@"SETTINGS_READ_RECEIPT", [readReceiptsSection
addItem:[OWSTableItem switchItemWithText:NSLocalizedString(@"SETTINGS_READ_RECEIPT",
@"Label for the 'read receipts' setting.") @"Label for the 'read receipts' setting.")
isOn:[self.readReceiptManager areReadReceiptsEnabled] isOnBlock:^{
return [OWSReadReceiptManager.sharedManager areReadReceiptsEnabled];
}
target:weakSelf target:weakSelf
selector:@selector(didToggleReadReceiptsSwitch:)]]; selector:@selector(didToggleReadReceiptsSwitch:)]];
[contents addSection:readReceiptsSection]; [contents addSection:readReceiptsSection];
@ -110,9 +113,12 @@ static NSString *const kSealedSenderInfoURL = @"https://signal.org/blog/sealed-s
= NSLocalizedString(@"SETTINGS_TYPING_INDICATORS", @"Label for the 'typing indicators' setting."); = NSLocalizedString(@"SETTINGS_TYPING_INDICATORS", @"Label for the 'typing indicators' setting.");
typingIndicatorsSection.footerTitle = NSLocalizedString( typingIndicatorsSection.footerTitle = NSLocalizedString(
@"SETTINGS_TYPING_INDICATORS_FOOTER", @"An explanation of the 'typing indicators' setting."); @"SETTINGS_TYPING_INDICATORS_FOOTER", @"An explanation of the 'typing indicators' setting.");
[typingIndicatorsSection addItem:[OWSTableItem switchItemWithText:NSLocalizedString(@"SETTINGS_TYPING_INDICATORS", [typingIndicatorsSection
addItem:[OWSTableItem switchItemWithText:NSLocalizedString(@"SETTINGS_TYPING_INDICATORS",
@"Label for the 'typing indicators' setting.") @"Label for the 'typing indicators' setting.")
isOn:[self.typingIndicators areTypingIndicatorsEnabled] isOnBlock:^{
return [SSKEnvironment.shared.typingIndicators areTypingIndicatorsEnabled];
}
target:weakSelf target:weakSelf
selector:@selector(didToggleTypingIndicatorsSwitch:)]]; selector:@selector(didToggleTypingIndicatorsSwitch:)]];
[contents addSection:typingIndicatorsSection]; [contents addSection:typingIndicatorsSection];
@ -126,7 +132,9 @@ static NSString *const kSealedSenderInfoURL = @"https://signal.org/blog/sealed-s
addItem:[OWSTableItem addItem:[OWSTableItem
switchItemWithText:NSLocalizedString(@"SETTINGS_SCREEN_LOCK_SWITCH_LABEL", switchItemWithText:NSLocalizedString(@"SETTINGS_SCREEN_LOCK_SWITCH_LABEL",
@"Label for the 'enable screen lock' switch of the privacy settings.") @"Label for the 'enable screen lock' switch of the privacy settings.")
isOn:OWSScreenLock.sharedManager.isScreenLockEnabled isOnBlock:^{
return [OWSScreenLock.sharedManager isScreenLockEnabled];
}
target:self target:self
selector:@selector(isScreenLockEnabledDidChange:)]]; selector:@selector(isScreenLockEnabledDidChange:)]];
[contents addSection:screenLockSection]; [contents addSection:screenLockSection];
@ -150,8 +158,11 @@ static NSString *const kSealedSenderInfoURL = @"https://signal.org/blog/sealed-s
OWSTableSection *screenSecuritySection = [OWSTableSection new]; OWSTableSection *screenSecuritySection = [OWSTableSection new];
screenSecuritySection.headerTitle = NSLocalizedString(@"SETTINGS_SECURITY_TITLE", @"Section header"); screenSecuritySection.headerTitle = NSLocalizedString(@"SETTINGS_SECURITY_TITLE", @"Section header");
screenSecuritySection.footerTitle = NSLocalizedString(@"SETTINGS_SCREEN_SECURITY_DETAIL", nil); screenSecuritySection.footerTitle = NSLocalizedString(@"SETTINGS_SCREEN_SECURITY_DETAIL", nil);
[screenSecuritySection addItem:[OWSTableItem switchItemWithText:NSLocalizedString(@"SETTINGS_SCREEN_SECURITY", @"") [screenSecuritySection
isOn:[self.preferences screenSecurityIsEnabled] addItem:[OWSTableItem switchItemWithText:NSLocalizedString(@"SETTINGS_SCREEN_SECURITY", @"")
isOnBlock:^{
return [Environment.shared.preferences screenSecurityIsEnabled];
}
target:weakSelf target:weakSelf
selector:@selector(didToggleScreenSecuritySwitch:)]]; selector:@selector(didToggleScreenSecuritySwitch:)]];
[contents addSection:screenSecuritySection]; [contents addSection:screenSecuritySection];
@ -165,7 +176,9 @@ static NSString *const kSealedSenderInfoURL = @"https://signal.org/blog/sealed-s
[callingSection addItem:[OWSTableItem switchItemWithText:NSLocalizedString( [callingSection addItem:[OWSTableItem switchItemWithText:NSLocalizedString(
@"SETTINGS_CALLING_HIDES_IP_ADDRESS_PREFERENCE_TITLE", @"SETTINGS_CALLING_HIDES_IP_ADDRESS_PREFERENCE_TITLE",
@"Table cell label") @"Table cell label")
isOn:[self.preferences doCallsHideIPAddress] isOnBlock:^{
return [Environment.shared.preferences doCallsHideIPAddress];
}
target:weakSelf target:weakSelf
selector:@selector(didToggleCallsHideIPAddressSwitch:)]]; selector:@selector(didToggleCallsHideIPAddressSwitch:)]];
[contents addSection:callingSection]; [contents addSection:callingSection];
@ -176,7 +189,9 @@ static NSString *const kSealedSenderInfoURL = @"https://signal.org/blog/sealed-s
addItem:[OWSTableItem switchItemWithText:NSLocalizedString( addItem:[OWSTableItem switchItemWithText:NSLocalizedString(
@"SETTINGS_PRIVACY_CALLKIT_SYSTEM_CALL_LOG_PREFERENCE_TITLE", @"SETTINGS_PRIVACY_CALLKIT_SYSTEM_CALL_LOG_PREFERENCE_TITLE",
@"Short table cell label") @"Short table cell label")
isOn:[self.preferences isSystemCallLogEnabled] isOnBlock:^{
return [Environment.shared.preferences isSystemCallLogEnabled];
}
target:weakSelf target:weakSelf
selector:@selector(didToggleEnableSystemCallLogSwitch:)]]; selector:@selector(didToggleEnableSystemCallLogSwitch:)]];
callKitSection.footerTitle = NSLocalizedString( callKitSection.footerTitle = NSLocalizedString(
@ -188,14 +203,19 @@ static NSString *const kSealedSenderInfoURL = @"https://signal.org/blog/sealed-s
= NSLocalizedString(@"SETTINGS_SECTION_CALL_KIT_DESCRIPTION", @"Settings table section footer."); = NSLocalizedString(@"SETTINGS_SECTION_CALL_KIT_DESCRIPTION", @"Settings table section footer.");
[callKitSection addItem:[OWSTableItem switchItemWithText:NSLocalizedString(@"SETTINGS_PRIVACY_CALLKIT_TITLE", [callKitSection addItem:[OWSTableItem switchItemWithText:NSLocalizedString(@"SETTINGS_PRIVACY_CALLKIT_TITLE",
@"Short table cell label") @"Short table cell label")
isOn:[self.preferences isCallKitEnabled] isOnBlock:^{
return [Environment.shared.preferences isCallKitEnabled];
}
target:weakSelf target:weakSelf
selector:@selector(didToggleEnableCallKitSwitch:)]]; selector:@selector(didToggleEnableCallKitSwitch:)]];
if (self.preferences.isCallKitEnabled) { if (self.preferences.isCallKitEnabled) {
[callKitSection [callKitSection
addItem:[OWSTableItem switchItemWithText:NSLocalizedString(@"SETTINGS_PRIVACY_CALLKIT_PRIVACY_TITLE", addItem:[OWSTableItem switchItemWithText:NSLocalizedString(@"SETTINGS_PRIVACY_CALLKIT_PRIVACY_TITLE",
@"Label for 'CallKit privacy' preference") @"Label for 'CallKit privacy' preference")
isOn:![self.preferences isCallKitPrivacyEnabled] isOnBlock:^{
return (BOOL) !
[Environment.shared.preferences isCallKitPrivacyEnabled];
}
target:weakSelf target:weakSelf
selector:@selector(didToggleEnableCallKitPrivacySwitch:)]]; selector:@selector(didToggleEnableCallKitPrivacySwitch:)]];
} }
@ -260,7 +280,7 @@ static NSString *const kSealedSenderInfoURL = @"https://signal.org/blog/sealed-s
UISwitch *cellSwitch = [UISwitch new]; UISwitch *cellSwitch = [UISwitch new];
cell.accessoryView = cellSwitch; cell.accessoryView = cellSwitch;
[cellSwitch setOn:weakSelf.preferences.shouldShowUnidentifiedDeliveryIndicators]; [cellSwitch setOn:Environment.shared.preferences.shouldShowUnidentifiedDeliveryIndicators];
[cellSwitch addTarget:weakSelf [cellSwitch addTarget:weakSelf
action:@selector(didToggleUDShowIndicatorsSwitch:) action:@selector(didToggleUDShowIndicatorsSwitch:)
forControlEvents:UIControlEventValueChanged]; forControlEvents:UIControlEventValueChanged];
@ -290,7 +310,9 @@ static NSString *const kSealedSenderInfoURL = @"https://signal.org/blog/sealed-s
OWSTableSection *unidentifiedDeliveryUnrestrictedSection = [OWSTableSection new]; OWSTableSection *unidentifiedDeliveryUnrestrictedSection = [OWSTableSection new];
OWSTableItem *unrestrictedAccessItem = [OWSTableItem OWSTableItem *unrestrictedAccessItem = [OWSTableItem
switchItemWithText:NSLocalizedString(@"SETTINGS_UNIDENTIFIED_DELIVERY_UNRESTRICTED_ACCESS", @"switch label") switchItemWithText:NSLocalizedString(@"SETTINGS_UNIDENTIFIED_DELIVERY_UNRESTRICTED_ACCESS", @"switch label")
isOn:weakSelf.udManager.shouldAllowUnrestrictedAccessLocal isOnBlock:^{
return [SSKEnvironment.shared.udManager shouldAllowUnrestrictedAccessLocal];
}
target:weakSelf target:weakSelf
selector:@selector(didToggleUDUnrestrictedAccessSwitch:)]; selector:@selector(didToggleUDUnrestrictedAccessSwitch:)];
[unidentifiedDeliveryUnrestrictedSection addItem:unrestrictedAccessItem]; [unidentifiedDeliveryUnrestrictedSection addItem:unrestrictedAccessItem];
@ -313,7 +335,9 @@ static NSString *const kSealedSenderInfoURL = @"https://signal.org/blog/sealed-s
[linkPreviewsSection [linkPreviewsSection
addItem:[OWSTableItem switchItemWithText:NSLocalizedString(@"SETTINGS_LINK_PREVIEWS", addItem:[OWSTableItem switchItemWithText:NSLocalizedString(@"SETTINGS_LINK_PREVIEWS",
@"Setting for enabling & disabling link previews.") @"Setting for enabling & disabling link previews.")
isOn:SSKPreferences.areLinkPreviewsEnabled isOnBlock:^{
return [SSKPreferences areLinkPreviewsEnabled];
}
target:weakSelf target:weakSelf
selector:@selector(didToggleLinkPreviewsEnabled:)]]; selector:@selector(didToggleLinkPreviewsEnabled:)]];
linkPreviewsSection.headerTitle = NSLocalizedString( linkPreviewsSection.headerTitle = NSLocalizedString(

@ -1122,6 +1122,7 @@ const CGFloat kIconViewLength = 24;
BOOL isCurrentlyBlocked = [self.blockingManager isThreadBlocked:self.thread]; BOOL isCurrentlyBlocked = [self.blockingManager isThreadBlocked:self.thread];
__weak OWSConversationSettingsViewController *weakSelf = self;
if (blockConversationSwitch.isOn) { if (blockConversationSwitch.isOn) {
OWSAssertDebug(!isCurrentlyBlocked); OWSAssertDebug(!isCurrentlyBlocked);
if (isCurrentlyBlocked) { if (isCurrentlyBlocked) {
@ -1135,6 +1136,8 @@ const CGFloat kIconViewLength = 24;
completionBlock:^(BOOL isBlocked) { completionBlock:^(BOOL isBlocked) {
// Update switch state if user cancels action. // Update switch state if user cancels action.
blockConversationSwitch.on = isBlocked; blockConversationSwitch.on = isBlocked;
[weakSelf updateTableContents];
}]; }];
} else { } else {
@ -1149,6 +1152,8 @@ const CGFloat kIconViewLength = 24;
completionBlock:^(BOOL isBlocked) { completionBlock:^(BOOL isBlocked) {
// Update switch state if user cancels action. // Update switch state if user cancels action.
blockConversationSwitch.on = isBlocked; blockConversationSwitch.on = isBlocked;
[weakSelf updateTableContents];
}]; }];
} }
} }

@ -1,5 +1,5 @@
// //
// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // Copyright (c) 2019 Open Whisper Systems. All rights reserved.
// //
#import <SignalMessaging/OWSViewController.h> #import <SignalMessaging/OWSViewController.h>
@ -47,6 +47,7 @@ extern const CGFloat kOWSTable_DefaultCellHeight;
typedef void (^OWSTableActionBlock)(void); typedef void (^OWSTableActionBlock)(void);
typedef void (^OWSTableSubPageBlock)(UIViewController *viewController); typedef void (^OWSTableSubPageBlock)(UIViewController *viewController);
typedef UITableViewCell *_Nonnull (^OWSTableCustomCellBlock)(void); typedef UITableViewCell *_Nonnull (^OWSTableCustomCellBlock)(void);
typedef BOOL (^OWSTableSwitchBlock)(void);
@interface OWSTableItem : NSObject @interface OWSTableItem : NSObject
@ -103,11 +104,14 @@ typedef UITableViewCell *_Nonnull (^OWSTableCustomCellBlock)(void);
+ (OWSTableItem *)longDisclosureItemWithText:(NSString *)text actionBlock:(nullable OWSTableActionBlock)actionBlock; + (OWSTableItem *)longDisclosureItemWithText:(NSString *)text actionBlock:(nullable OWSTableActionBlock)actionBlock;
+ (OWSTableItem *)switchItemWithText:(NSString *)text isOn:(BOOL)isOn target:(id)target selector:(SEL)selector; + (OWSTableItem *)switchItemWithText:(NSString *)text
isOnBlock:(OWSTableSwitchBlock)isOnBlock
target:(id)target
selector:(SEL)selector;
+ (OWSTableItem *)switchItemWithText:(NSString *)text + (OWSTableItem *)switchItemWithText:(NSString *)text
isOn:(BOOL)isOn isOnBlock:(OWSTableSwitchBlock)isOnBlock
isEnabled:(BOOL)isEnabled isEnabledBlock:(OWSTableSwitchBlock)isEnabledBlock
target:(id)target target:(id)target
selector:(SEL)selector; selector:(SEL)selector;

@ -366,14 +366,23 @@ const CGFloat kOWSTable_DefaultCellHeight = 45.f;
return item; return item;
} }
+ (OWSTableItem *)switchItemWithText:(NSString *)text isOn:(BOOL)isOn target:(id)target selector:(SEL)selector + (OWSTableItem *)switchItemWithText:(NSString *)text
isOnBlock:(OWSTableSwitchBlock)isOnBlock
target:(id)target
selector:(SEL)selector
{ {
return [self switchItemWithText:text isOn:isOn isEnabled:YES target:target selector:selector]; return [self switchItemWithText:text
isOnBlock:(OWSTableSwitchBlock)isOnBlock
isEnabledBlock:^{
return YES;
}
target:target
selector:selector];
} }
+ (OWSTableItem *)switchItemWithText:(NSString *)text + (OWSTableItem *)switchItemWithText:(NSString *)text
isOn:(BOOL)isOn isOnBlock:(OWSTableSwitchBlock)isOnBlock
isEnabled:(BOOL)isEnabled isEnabledBlock:(OWSTableSwitchBlock)isEnabledBlock
target:(id)target target:(id)target
selector:(SEL)selector selector:(SEL)selector
{ {
@ -389,9 +398,9 @@ const CGFloat kOWSTable_DefaultCellHeight = 45.f;
UISwitch *cellSwitch = [UISwitch new]; UISwitch *cellSwitch = [UISwitch new];
cell.accessoryView = cellSwitch; cell.accessoryView = cellSwitch;
[cellSwitch setOn:isOn]; [cellSwitch setOn:isOnBlock()];
[cellSwitch addTarget:weakTarget action:selector forControlEvents:UIControlEventValueChanged]; [cellSwitch addTarget:weakTarget action:selector forControlEvents:UIControlEventValueChanged];
cellSwitch.enabled = isEnabled; cellSwitch.enabled = isEnabledBlock();
cell.selectionStyle = UITableViewCellSelectionStyleNone; cell.selectionStyle = UITableViewCellSelectionStyleNone;

Loading…
Cancel
Save