From 866a724ac20900a959bdaebd42202a2c94d608b3 Mon Sep 17 00:00:00 2001 From: Ilya Grechuhin Date: Wed, 12 Oct 2016 13:36:35 +0300 Subject: [PATCH] [ios] Fixed weak property multiple times access. Weak property is accessed multiple times in this method but may be unpredictably set to nil; assign to a strong variable to keep the object alive. --- iphone/Maps/Classes/ContextViews.mm | 1 - .../Classes/CustomAlert/BaseAlert/MWMAlert.mm | 8 +- .../CustomAlert/RateAlert/MWMRateAlert.mm | 9 +- .../MapViewControls/APIBar/MWMAPIBar.mm | 13 +-- .../BottomMenu/MWMBottomMenuViewController.mm | 8 +- .../MWMMapViewControlsManager.mm | 14 ++-- .../MWMPlacePageOpeningHoursCell.mm | 5 +- .../MWMSearchCategoriesManager.mm | 7 +- .../HistoryTab/MWMSearchHistoryManager.mm | 5 +- .../MWMSearchTabbedViewController.mm | 13 +-- .../TableView/MWMSearchTableViewController.mm | 11 +-- .../Welcome/MWMWhatsNewEditorController.mm | 5 +- .../PageController/MWMPageController.mm | 9 +- .../MWMNavigationDashboardManager.mm | 5 +- iphone/Maps/Classes/Editor/MWMNoteCell.mm | 5 +- .../MWMObjectsCategorySelectorController.mm | 5 +- .../MWMOpeningHoursClosedSpanTableViewCell.mm | 9 +- ...WMOpeningHoursDaysSelectorTableViewCell.mm | 5 +- .../MWMOpeningHoursTimeSpanTableViewCell.mm | 6 +- .../OpeningHours/MWMOpeningHoursModel.mm | 13 +-- .../OpeningHours/MWMOpeningHoursSection.mm | 10 ++- .../Street/MWMStreetEditorViewController.mm | 10 ++- iphone/Maps/Classes/MWMBasePlacePageView.mm | 2 +- iphone/Maps/Classes/MWMPlacePage.mm | 13 +-- iphone/Maps/Classes/MWMPlacePageActionBar.mm | 17 ++-- iphone/Maps/Classes/MWMPlacePageButtonCell.mm | 9 +- .../Cells/MWMMapDownloaderTableViewCell.mm | 11 +-- .../MWMBaseMapDownloaderViewController.mm | 2 +- iphone/Maps/Classes/Search/MWMSearch.mm | 82 ++++++++++--------- .../Classes/Widgets/MWMMapDownloadDialog.mm | 10 ++- iphone/Maps/MWMNightModeController.mm | 10 ++- .../Maps/MWMRecentTrackSettingsController.mm | 8 +- iphone/Maps/MWMUnitsController.mm | 9 +- 33 files changed, 196 insertions(+), 153 deletions(-) diff --git a/iphone/Maps/Classes/ContextViews.mm b/iphone/Maps/Classes/ContextViews.mm index f1a98b4ef1..efeaa98062 100755 --- a/iphone/Maps/Classes/ContextViews.mm +++ b/iphone/Maps/Classes/ContextViews.mm @@ -26,5 +26,4 @@ { [UIPasteboard generalPasteboard].string = self.text; } - @end diff --git a/iphone/Maps/Classes/CustomAlert/BaseAlert/MWMAlert.mm b/iphone/Maps/Classes/CustomAlert/BaseAlert/MWMAlert.mm index 0750026ace..8c7d98110b 100644 --- a/iphone/Maps/Classes/CustomAlert/BaseAlert/MWMAlert.mm +++ b/iphone/Maps/Classes/CustomAlert/BaseAlert/MWMAlert.mm @@ -212,11 +212,11 @@ CGAffineTransform rotation(UIInterfaceOrientation orientation) { _alertController = alertController; UIView * view = alertController.view; - UIView * ownerView = alertController.ownerViewController.view; - view.frame = ownerView.bounds; - [alertController.ownerViewController.view addSubview:view]; + UIViewController * ownerViewController = alertController.ownerViewController; + view.frame = ownerViewController.view.bounds; + [ownerViewController.view addSubview:view]; [self addControllerViewToWindow]; - [self rotate:alertController.ownerViewController.interfaceOrientation duration:0.0]; + [self rotate:ownerViewController.interfaceOrientation duration:0.0]; [view addSubview:self]; self.frame = view.bounds; } diff --git a/iphone/Maps/Classes/CustomAlert/RateAlert/MWMRateAlert.mm b/iphone/Maps/Classes/CustomAlert/RateAlert/MWMRateAlert.mm index b79e88640a..4b1bd19697 100644 --- a/iphone/Maps/Classes/CustomAlert/RateAlert/MWMRateAlert.mm +++ b/iphone/Maps/Classes/CustomAlert/RateAlert/MWMRateAlert.mm @@ -142,7 +142,8 @@ static NSString * const kStatisticsEvent = @"Rate Alert"; [Statistics logEvent:kStatEventName(kStatisticsEvent, kStatSendEmail)]; [Alohalytics logEvent:kRateAlertEventName withValue:@"sendFeedback"]; self.alpha = 0.; - self.alertController.view.alpha = 0.; + MWMAlertViewController * alertController = self.alertController; + alertController.view.alpha = 0.; if ([MFMailComposeViewController canSendMail]) { struct utsname systemInfo; @@ -170,9 +171,9 @@ static NSString * const kStatisticsEvent = @"Rate Alert"; [mailController setToRecipients:@[ kRateEmail ]]; [mailController setMessageBody:text isHTML:NO]; mailController.navigationBar.tintColor = [UIColor blackColor]; - [self.alertController.ownerViewController presentViewController:mailController - animated:YES - completion:nil]; + [alertController.ownerViewController presentViewController:mailController + animated:YES + completion:nil]; } else { diff --git a/iphone/Maps/Classes/CustomViews/MapViewControls/APIBar/MWMAPIBar.mm b/iphone/Maps/Classes/CustomViews/MapViewControls/APIBar/MWMAPIBar.mm index 35c5ae09d7..a6d4e65008 100644 --- a/iphone/Maps/Classes/CustomViews/MapViewControls/APIBar/MWMAPIBar.mm +++ b/iphone/Maps/Classes/CustomViews/MapViewControls/APIBar/MWMAPIBar.mm @@ -82,15 +82,16 @@ static NSString * const kKeyPath = @"subviews"; if (_isVisible == isVisible) return; _isVisible = isVisible; + UIViewController * controller = self.controller; if (isVisible) { self.backLabel.text = [NSString stringWithFormat:L(@"back_to"), @(GetFramework().GetApiDataHolder().GetAppTitle().c_str())]; - [self.controller.view addSubview:self.rootView]; - [self.controller.view addObserver:self - forKeyPath:kKeyPath - options:NSKeyValueObservingOptionNew - context:nullptr]; + [controller.view addSubview:self.rootView]; + [controller.view addObserver:self + forKeyPath:kKeyPath + options:NSKeyValueObservingOptionNew + context:nullptr]; [self timerUpdate]; self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self @@ -104,7 +105,7 @@ static NSString * const kKeyPath = @"subviews"; [self.rootView removeFromSuperview]; [self.timer invalidate]; } - [self.controller setNeedsStatusBarAppearanceUpdate]; + [controller setNeedsStatusBarAppearanceUpdate]; } @end diff --git a/iphone/Maps/Classes/CustomViews/MapViewControls/BottomMenu/MWMBottomMenuViewController.mm b/iphone/Maps/Classes/CustomViews/MapViewControls/BottomMenu/MWMBottomMenuViewController.mm index f93afcd095..aaff11b88a 100644 --- a/iphone/Maps/Classes/CustomViews/MapViewControls/BottomMenu/MWMBottomMenuViewController.mm +++ b/iphone/Maps/Classes/CustomViews/MapViewControls/BottomMenu/MWMBottomMenuViewController.mm @@ -552,10 +552,10 @@ typedef NS_ENUM(NSUInteger, MWMBottomMenuViewCell) { - (void)setTtsSoundButton:(MWMButton *)ttsSoundButton { _ttsSoundButton = ttsSoundButton; - [_ttsSoundButton setImage:[UIImage imageNamed:@"ic_voice_on"] forState:UIControlStateNormal]; - [_ttsSoundButton setImage:[UIImage imageNamed:@"ic_voice_off"] forState:UIControlStateSelected]; - [_ttsSoundButton setImage:[UIImage imageNamed:@"ic_voice_off"] - forState:UIControlStateSelected | UIControlStateHighlighted]; + [ttsSoundButton setImage:[UIImage imageNamed:@"ic_voice_on"] forState:UIControlStateNormal]; + [ttsSoundButton setImage:[UIImage imageNamed:@"ic_voice_off"] forState:UIControlStateSelected]; + [ttsSoundButton setImage:[UIImage imageNamed:@"ic_voice_off"] + forState:UIControlStateSelected | UIControlStateHighlighted]; [self ttsButtonStatusChanged:nil]; } diff --git a/iphone/Maps/Classes/CustomViews/MapViewControls/MWMMapViewControlsManager.mm b/iphone/Maps/Classes/CustomViews/MapViewControls/MWMMapViewControlsManager.mm index 3c87ec2b15..cb8531151d 100644 --- a/iphone/Maps/Classes/CustomViews/MapViewControls/MWMMapViewControlsManager.mm +++ b/iphone/Maps/Classes/CustomViews/MapViewControls/MWMMapViewControlsManager.mm @@ -213,6 +213,7 @@ extern NSString * const kAlohalyticsTapEventKey; - (void)actionDownloadMaps:(mwm::DownloaderMode)mode { + MapViewController * ownerController = self.ownerController; if (platform::migrate::NeedMigrate()) { if (GetFramework().IsRoutingActive()) @@ -225,12 +226,12 @@ extern NSString * const kAlohalyticsTapEventKey; { [Statistics logEvent:kStatDownloaderMigrationDialogue withParameters:@{kStatFrom : kStatDownloader}]; - [self.ownerController openMigration]; + [ownerController openMigration]; } } else { - [self.ownerController openMapsDownloader:mode]; + [ownerController openMapsDownloader:mode]; } } @@ -259,11 +260,12 @@ extern NSString * const kAlohalyticsTapEventKey; - (void)addPlace:(BOOL)isBusiness hasPoint:(BOOL)hasPoint point:(m2::PointD const &)point { self.menuState = MWMBottomMenuStateHidden; - static_cast(self.ownerController.view).widgetsManager.fullScreen = YES; + MapViewController * ownerController = self.ownerController; + static_cast(ownerController.view).widgetsManager.fullScreen = YES; [self.placePageManager dismissPlacePage]; self.searchManager.state = MWMSearchManagerStateHidden; - [MWMAddPlaceNavigationBar showInSuperview:self.ownerController.view + [MWMAddPlaceNavigationBar showInSuperview:ownerController.view isBusiness:isBusiness applyPosition:hasPoint position:point @@ -272,9 +274,9 @@ extern NSString * const kAlohalyticsTapEventKey; if (IsPointCoveredByDownloadedMaps(f.GetViewportCenter(), f.GetStorage(), f.GetCountryInfoGetter())) - [self.ownerController performSegueWithIdentifier:kMapToCategorySelectorSegue sender:nil]; + [ownerController performSegueWithIdentifier:kMapToCategorySelectorSegue sender:nil]; else - [self.ownerController.alertController presentIncorrectFeauturePositionAlert]; + [ownerController.alertController presentIncorrectFeauturePositionAlert]; [self didFinishAddingPlace]; } diff --git a/iphone/Maps/Classes/CustomViews/MapViewControls/PlacePage/Cells/OpeningHours/MWMPlacePageOpeningHoursCell.mm b/iphone/Maps/Classes/CustomViews/MapViewControls/PlacePage/Cells/OpeningHours/MWMPlacePageOpeningHoursCell.mm index 2817f85955..5d0a01d227 100644 --- a/iphone/Maps/Classes/CustomViews/MapViewControls/PlacePage/Cells/OpeningHours/MWMPlacePageOpeningHoursCell.mm +++ b/iphone/Maps/Classes/CustomViews/MapViewControls/PlacePage/Cells/OpeningHours/MWMPlacePageOpeningHoursCell.mm @@ -123,11 +123,12 @@ WeekDayView getWeekDayView() } if (!haveCurrentDay) [self addEmptyCurrentDay]; + id delegate = self.delegate; if (self.haveExpandSchedule) { self.toggleButton.hidden = NO; self.expandImage.hidden = NO; - if (self.delegate.forcedButton) + if (delegate.forcedButton) self.expandImage.image = [UIImage imageNamed:@"ic_arrow_gray_right"]; else if (self.isExpanded) self.expandImage.image = [UIImage imageNamed:@"ic_arrow_gray_up"]; @@ -142,7 +143,7 @@ WeekDayView getWeekDayView() [self addClosedDays]; } self.openTimeTrailingOffset.priority = - self.delegate.forcedButton ? UILayoutPriorityDefaultHigh : UILayoutPriorityDefaultLow; + delegate.forcedButton ? UILayoutPriorityDefaultHigh : UILayoutPriorityDefaultLow; self.weekDaysViewHeight.constant = ceil(self.weekDaysViewEstimatedHeight); [self alignTimeOffsets]; } diff --git a/iphone/Maps/Classes/CustomViews/MapViewControls/Search/TabbedView/CategoriesTab/MWMSearchCategoriesManager.mm b/iphone/Maps/Classes/CustomViews/MapViewControls/Search/TabbedView/CategoriesTab/MWMSearchCategoriesManager.mm index 7a9af94411..51ce5023c3 100644 --- a/iphone/Maps/Classes/CustomViews/MapViewControls/Search/TabbedView/CategoriesTab/MWMSearchCategoriesManager.mm +++ b/iphone/Maps/Classes/CustomViews/MapViewControls/Search/TabbedView/CategoriesTab/MWMSearchCategoriesManager.mm @@ -68,9 +68,10 @@ static NSString * const kCellIdentifier = @"MWMSearchCategoryCell"; NSString * string = @(m_categories[indexPath.row].c_str()); [Statistics logEvent:kStatEventName(kStatSearch, kStatSelectResult) withParameters:@{kStatValue : string, kStatScreen : kStatCategories}]; - [self.delegate searchText:[L(string) stringByAppendingString:@" "] - forInputLocale:[[AppInfo sharedInfo] languageId]]; - [self.delegate dismissKeyboard]; + id delegate = self.delegate; + [delegate searchText:[L(string) stringByAppendingString:@" "] + forInputLocale:[[AppInfo sharedInfo] languageId]]; + [delegate dismissKeyboard]; } @end diff --git a/iphone/Maps/Classes/CustomViews/MapViewControls/Search/TabbedView/HistoryTab/MWMSearchHistoryManager.mm b/iphone/Maps/Classes/CustomViews/MapViewControls/Search/TabbedView/HistoryTab/MWMSearchHistoryManager.mm index 592cb860f7..5e566bfbdb 100644 --- a/iphone/Maps/Classes/CustomViews/MapViewControls/Search/TabbedView/HistoryTab/MWMSearchHistoryManager.mm +++ b/iphone/Maps/Classes/CustomViews/MapViewControls/Search/TabbedView/HistoryTab/MWMSearchHistoryManager.mm @@ -142,6 +142,7 @@ static NSString * const kMyPositionCellIdentifier = @"MWMSearchHistoryMyPosition - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { BOOL const isRouteSearch = self.isRouteSearchMode; + id delegate = self.delegate; if ([self isRequestCell:indexPath]) { search::QuerySaver::TSearchRequest const & query = @@ -149,7 +150,7 @@ static NSString * const kMyPositionCellIdentifier = @"MWMSearchHistoryMyPosition NSString * queryText = @(query.second.c_str()); [Statistics logEvent:kStatEventName(kStatSearch, kStatSelectResult) withParameters:@{kStatValue : queryText, kStatScreen : kStatHistory}]; - [self.delegate searchText:queryText forInputLocale:@(query.first.c_str())]; + [delegate searchText:queryText forInputLocale:@(query.first.c_str())]; } else { @@ -157,7 +158,7 @@ static NSString * const kMyPositionCellIdentifier = @"MWMSearchHistoryMyPosition { [Statistics logEvent:kStatEventName(kStatSearch, kStatSelectResult) withParameters:@{kStatValue : kStatMyPosition, kStatScreen : kStatHistory}]; - [self.delegate tapMyPositionFromHistory]; + [delegate tapMyPositionFromHistory]; return; } [Statistics logEvent:kStatEventName(kStatSearch, kStatSelectResult) diff --git a/iphone/Maps/Classes/CustomViews/MapViewControls/Search/TabbedView/MWMSearchTabbedViewController.mm b/iphone/Maps/Classes/CustomViews/MapViewControls/Search/TabbedView/MWMSearchTabbedViewController.mm index 4f82e2294e..cd5b977f92 100644 --- a/iphone/Maps/Classes/CustomViews/MapViewControls/Search/TabbedView/MWMSearchTabbedViewController.mm +++ b/iphone/Maps/Classes/CustomViews/MapViewControls/Search/TabbedView/MWMSearchTabbedViewController.mm @@ -142,13 +142,15 @@ BOOL isOffsetInButton(CGFloat offset, MWMSearchTabButtonsView * button) - (void)updateScrollPosition:(CGFloat)position { - CGFloat const btnMid = position + 0.5 * self.scrollIndicator.width; + CGFloat const scrollIndicatorWidth = self.scrollIndicator.width; + CGFloat const btnMid = position + 0.5 * scrollIndicatorWidth; if (isInterfaceRightToLeft()) - position = self.scrollIndicator.width - position; + position = scrollIndicatorWidth - position; runAsyncOnMainQueue(^{ self.scrollIndicatorOffset.constant = nearbyint(position); }); - if (self.selectedButton && isOffsetInButton(btnMid, self.selectedButton)) + MWMSearchTabButtonsView * selectedButton = self.selectedButton; + if (selectedButton && isOffsetInButton(btnMid, selectedButton)) return; [self.tabButtons enumerateObjectsUsingBlock:^(MWMSearchTabButtonsView * btn, NSUInteger idx, BOOL * stop) { @@ -174,8 +176,9 @@ BOOL isOffsetInButton(CGFloat offset, MWMSearchTabButtonsView * button) - (void)refreshScrollPosition { - self.scrollIndicatorOffset.constant = nearbyint(self.selectedButton.minX); - [self tabButtonPressed:self.selectedButton]; + MWMSearchTabButtonsView * selectedButton = self.selectedButton; + self.scrollIndicatorOffset.constant = nearbyint(selectedButton.minX); + [self tabButtonPressed:selectedButton]; } #pragma mark - UICollectionViewDataSource diff --git a/iphone/Maps/Classes/CustomViews/MapViewControls/Search/TableView/MWMSearchTableViewController.mm b/iphone/Maps/Classes/CustomViews/MapViewControls/Search/TableView/MWMSearchTableViewController.mm index 4b4e9fd23b..62466ab609 100644 --- a/iphone/Maps/Classes/CustomViews/MapViewControls/Search/TableView/MWMSearchTableViewController.mm +++ b/iphone/Maps/Classes/CustomViews/MapViewControls/Search/TableView/MWMSearchTableViewController.mm @@ -203,11 +203,12 @@ NSString * identifierForType(MWMSearchTableCellType type) - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { MWMSearchTableCellType cellType = [self cellTypeForIndexPath:indexPath]; + id delegate = self.delegate; if (cellType == MWMSearchTableCellTypeOnMap) { - MWMSearchTextField * textField = self.delegate.searchTextField; + MWMSearchTextField * textField = delegate.searchTextField; [MWMSearch saveQuery:textField.text forInputLocale:textField.textInputMode.primaryLanguage]; - self.delegate.state = MWMSearchManagerStateMapSearch; + delegate.state = MWMSearchManagerStateMapSearch; } else { @@ -217,13 +218,13 @@ NSString * identifierForType(MWMSearchTableCellType type) NSString * suggestionString = @(result.GetSuggestionString()); [Statistics logEvent:kStatEventName(kStatSearch, kStatSelectResult) withParameters:@{kStatValue : suggestionString, kStatScreen : kStatSearch}]; - [self.delegate searchText:suggestionString forInputLocale:nil]; + [delegate searchText:suggestionString forInputLocale:nil]; } else { - MWMSearchTextField * textField = self.delegate.searchTextField; + MWMSearchTextField * textField = delegate.searchTextField; [MWMSearch saveQuery:textField.text forInputLocale:textField.textInputMode.primaryLanguage]; - [self.delegate processSearchWithResult:result]; + [delegate processSearchWithResult:result]; } } } diff --git a/iphone/Maps/Classes/CustomViews/MapViewControls/Welcome/MWMWhatsNewEditorController.mm b/iphone/Maps/Classes/CustomViews/MapViewControls/Welcome/MWMWhatsNewEditorController.mm index b19a9fc8f7..52288b14ce 100644 --- a/iphone/Maps/Classes/CustomViews/MapViewControls/Welcome/MWMWhatsNewEditorController.mm +++ b/iphone/Maps/Classes/CustomViews/MapViewControls/Welcome/MWMWhatsNewEditorController.mm @@ -32,6 +32,7 @@ NSArray * pagesConfigBlocks = @[ [^(MWMWhatsNewEditorController * controller) { controller.image.image = [UIImage imageNamed:@"img_editor_upd"]; controller.alertTitle.text = L(@"whatsnew_update_editor_title"); + MWMPageController * pageController = controller.pageController; if (platform::migrate::NeedMigrate()) { controller.alertText.text = @@ -44,7 +45,7 @@ NSArray * pagesConfigBlocks = @[ forControlEvents:UIControlEventTouchUpInside]; [controller.secondaryButton setTitle:L(@"not_now") forState:UIControlStateNormal]; - [controller.secondaryButton addTarget:controller.pageController + [controller.secondaryButton addTarget:pageController action:@selector(close) forControlEvents:UIControlEventTouchUpInside]; } @@ -55,7 +56,7 @@ NSArray * pagesConfigBlocks = @[ controller.buttonsSpacing.priority = UILayoutPriorityDefaultLow; [controller.primaryButton setTitle:L(@"done") forState:UIControlStateNormal]; - [controller.primaryButton addTarget:controller.pageController + [controller.primaryButton addTarget:pageController action:@selector(close) forControlEvents:UIControlEventTouchUpInside]; } diff --git a/iphone/Maps/Classes/CustomViews/MapViewControls/Welcome/PageController/MWMPageController.mm b/iphone/Maps/Classes/CustomViews/MapViewControls/Welcome/PageController/MWMPageController.mm index 327033ba9e..1691aa1fe5 100644 --- a/iphone/Maps/Classes/CustomViews/MapViewControls/Welcome/PageController/MWMPageController.mm +++ b/iphone/Maps/Classes/CustomViews/MapViewControls/Welcome/PageController/MWMPageController.mm @@ -63,11 +63,12 @@ [Statistics logEvent:kStatEventName(kStatWhatsNew, [self.welcomeClass udWelcomeWasShownKey]) withParameters:@{kStatAction : kStatOpen}]; [self configure]; + UIViewController * parent = self.parent; if (IPAD) - [self.parent.view addSubview:self.iPadBackgroundView]; - [self.parent addChildViewController:self]; - [self.parent.view addSubview:self.view]; - [self didMoveToParentViewController:self.parent]; + [parent.view addSubview:self.iPadBackgroundView]; + [parent addChildViewController:self]; + [parent.view addSubview:self.view]; + [self didMoveToParentViewController:parent]; } #pragma mark - Private methods diff --git a/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationDashboardManager.mm b/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationDashboardManager.mm index 89bb10afdc..94ecdcff22 100644 --- a/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationDashboardManager.mm +++ b/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationDashboardManager.mm @@ -152,8 +152,9 @@ using TInfoDisplays = NSHashTable<__kindof TInfoDisplay>; - (void)setMenuState:(MWMBottomMenuState)menuState { - [self.delegate setMenuState:menuState]; - [self.delegate setMenuRestoreState:menuState]; + id delegate = self.delegate; + [delegate setMenuState:menuState]; + [delegate setMenuRestoreState:menuState]; } - (void)mwm_refreshUI diff --git a/iphone/Maps/Classes/Editor/MWMNoteCell.mm b/iphone/Maps/Classes/Editor/MWMNoteCell.mm index 4fc4011bf1..42ce5332b0 100644 --- a/iphone/Maps/Classes/Editor/MWMNoteCell.mm +++ b/iphone/Maps/Classes/Editor/MWMNoteCell.mm @@ -33,10 +33,11 @@ static void * kContext = &kContext; - (void)updateTextViewForHeight:(CGFloat)height { + id delegate = self.delegate; if (height > kMinimalTextViewHeight) { self.textViewHeight.constant = height; - [self.delegate cellShouldChangeSize:self text:self.textView.text]; + [delegate cellShouldChangeSize:self text:self.textView.text]; } else { @@ -44,7 +45,7 @@ static void * kContext = &kContext; if (currentHeight > kMinimalTextViewHeight) { self.textViewHeight.constant = kMinimalTextViewHeight; - [self.delegate cellShouldChangeSize:self text:self.textView.text]; + [delegate cellShouldChangeSize:self text:self.textView.text]; } } diff --git a/iphone/Maps/Classes/Editor/MWMObjectsCategorySelectorController.mm b/iphone/Maps/Classes/Editor/MWMObjectsCategorySelectorController.mm index 49e1fd4596..2f8b761d27 100644 --- a/iphone/Maps/Classes/Editor/MWMObjectsCategorySelectorController.mm +++ b/iphone/Maps/Classes/Editor/MWMObjectsCategorySelectorController.mm @@ -85,10 +85,11 @@ string locale() - (void)backTap { - if (self.delegate) + id delegate = self.delegate; + if (delegate) { auto const object = self.createdObject; - [self.delegate reloadObject:object]; + [delegate reloadObject:object]; } [super backTap]; } diff --git a/iphone/Maps/Classes/Editor/OpeningHours/Cells/MWMOpeningHoursClosedSpanTableViewCell.mm b/iphone/Maps/Classes/Editor/OpeningHours/Cells/MWMOpeningHoursClosedSpanTableViewCell.mm index 8e04f5f8c4..238f33141d 100644 --- a/iphone/Maps/Classes/Editor/OpeningHours/Cells/MWMOpeningHoursClosedSpanTableViewCell.mm +++ b/iphone/Maps/Classes/Editor/OpeningHours/Cells/MWMOpeningHoursClosedSpanTableViewCell.mm @@ -91,8 +91,8 @@ BOOL isCompactForCellWidth(CGFloat width) self.timeSpanLabel.text = [NSString stringWithFormat:@"%@-%@", openString, closeString]; - self.timeSpanLabel.textColor = - [self.section isRowSelected:row] ? [UIColor linkBlue] : [UIColor blackSecondaryText]; + BOOL const isRowSelected = [section isRowSelected:row]; + self.timeSpanLabel.textColor = isRowSelected ? [UIColor linkBlue] : [UIColor blackSecondaryText]; } #pragma mark - Actions @@ -103,8 +103,9 @@ BOOL isCompactForCellWidth(CGFloat width) if (!self.isVisible) return; NSUInteger const row = self.row; - self.section.selectedRow = [self.section isRowSelected:row] ? nil : @(row); - [self.section refresh:NO]; + MWMOpeningHoursSection * section = self.section; + section.selectedRow = [section isRowSelected:row] ? nil : @(row); + [section refresh:NO]; } @end diff --git a/iphone/Maps/Classes/Editor/OpeningHours/Cells/MWMOpeningHoursDaysSelectorTableViewCell.mm b/iphone/Maps/Classes/Editor/OpeningHours/Cells/MWMOpeningHoursDaysSelectorTableViewCell.mm index 1c47b4641a..e85e44776a 100644 --- a/iphone/Maps/Classes/Editor/OpeningHours/Cells/MWMOpeningHoursDaysSelectorTableViewCell.mm +++ b/iphone/Maps/Classes/Editor/OpeningHours/Cells/MWMOpeningHoursDaysSelectorTableViewCell.mm @@ -55,10 +55,11 @@ using namespace osmoh; if (refresh) { Weekday const wd = [self tag2Weekday:tag]; + MWMOpeningHoursSection * section = self.section; if (selected) - [self.section addSelectedDay:wd]; + [section addSelectedDay:wd]; else - [self.section removeSelectedDay:wd]; + [section removeSelectedDay:wd]; } for (UIButton * btn in self.buttons) { diff --git a/iphone/Maps/Classes/Editor/OpeningHours/Cells/MWMOpeningHoursTimeSpanTableViewCell.mm b/iphone/Maps/Classes/Editor/OpeningHours/Cells/MWMOpeningHoursTimeSpanTableViewCell.mm index 8bc18bfb7f..70add3faee 100644 --- a/iphone/Maps/Classes/Editor/OpeningHours/Cells/MWMOpeningHoursTimeSpanTableViewCell.mm +++ b/iphone/Maps/Classes/Editor/OpeningHours/Cells/MWMOpeningHoursTimeSpanTableViewCell.mm @@ -35,7 +35,7 @@ self.openTimeLabel.text = [dateFormatter stringFromDate:openDate]; self.closeTimeLabel.text = [dateFormatter stringFromDate:closeDate]; - UIColor * clr = [self.section isRowSelected:row] ? [UIColor linkBlue] : [UIColor blackSecondaryText]; + UIColor * clr = [section isRowSelected:row] ? [UIColor linkBlue] : [UIColor blackSecondaryText]; self.openTimeLabel.textColor = clr; self.closeTimeLabel.textColor = clr; } @@ -48,8 +48,8 @@ { MWMOpeningHoursSection * section = self.section; NSUInteger const row = self.row; - section.selectedRow = [self.section isRowSelected:row] ? nil : @(row); - [self.section refresh:NO]; + section.selectedRow = [section isRowSelected:row] ? nil : @(row); + [section refresh:NO]; } } diff --git a/iphone/Maps/Classes/Editor/OpeningHours/MWMOpeningHoursModel.mm b/iphone/Maps/Classes/Editor/OpeningHours/MWMOpeningHoursModel.mm index 3ce129bb39..583bc3ecd7 100644 --- a/iphone/Maps/Classes/Editor/OpeningHours/MWMOpeningHoursModel.mm +++ b/iphone/Maps/Classes/Editor/OpeningHours/MWMOpeningHoursModel.mm @@ -64,18 +64,19 @@ using namespace osmoh; timeTableSet.Remove(index); [self.sections removeObjectAtIndex:index]; [self refreshSectionsIndexes]; + UITableView * tableView = self.tableView; if (needRealDelete) { - [self.tableView deleteSections:[[NSIndexSet alloc] initWithIndex:index] - withRowAnimation:kMWMOpeningHoursEditorRowAnimation]; - [self.tableView reloadSections:[[NSIndexSet alloc] initWithIndex:self.count] - withRowAnimation:kMWMOpeningHoursEditorRowAnimation]; + [tableView deleteSections:[[NSIndexSet alloc] initWithIndex:index] + withRowAnimation:kMWMOpeningHoursEditorRowAnimation]; + [tableView reloadSections:[[NSIndexSet alloc] initWithIndex:self.count] + withRowAnimation:kMWMOpeningHoursEditorRowAnimation]; } else { NSRange reloadRange = {index, self.count - index + 1}; - [self.tableView reloadSections:[[NSIndexSet alloc] initWithIndexesInRange:reloadRange] - withRowAnimation:kMWMOpeningHoursEditorRowAnimation]; + [tableView reloadSections:[[NSIndexSet alloc] initWithIndexesInRange:reloadRange] + withRowAnimation:kMWMOpeningHoursEditorRowAnimation]; } } diff --git a/iphone/Maps/Classes/Editor/OpeningHours/MWMOpeningHoursSection.mm b/iphone/Maps/Classes/Editor/OpeningHours/MWMOpeningHoursSection.mm index a07dd1f9a5..d504a7d586 100644 --- a/iphone/Maps/Classes/Editor/OpeningHours/MWMOpeningHoursSection.mm +++ b/iphone/Maps/Classes/Editor/OpeningHours/MWMOpeningHoursSection.mm @@ -266,12 +266,13 @@ using namespace osmoh; - (void)refresh:(BOOL)force { + UITableView * tableView = self.delegate.tableView; if (force) { - [self.delegate.tableView reloadData]; + [tableView reloadData]; return; } - for (MWMOpeningHoursTableViewCell * cell in self.delegate.tableView.visibleCells) + for (MWMOpeningHoursTableViewCell * cell in tableView.visibleCells) { [cell refresh]; } @@ -344,14 +345,15 @@ using namespace osmoh; NSUInteger const newInd = selectedRow.unsignedIntegerValue; NSUInteger const oldInd = oldSelectedRow.unsignedIntegerValue; - UITableView * tableView = self.delegate.tableView; + id delegate = self.delegate; + UITableView * tableView = delegate.tableView; [tableView beginUpdates]; if (!oldSelectedRow) { _selectedRow = selectedRow; [self insertRow:newInd + 1]; - [self.delegate updateActiveSection:self.index]; + [delegate updateActiveSection:self.index]; } else if (selectedRow) { diff --git a/iphone/Maps/Classes/Editor/Street/MWMStreetEditorViewController.mm b/iphone/Maps/Classes/Editor/Street/MWMStreetEditorViewController.mm index 6db6b2e185..7367f81049 100644 --- a/iphone/Maps/Classes/Editor/Street/MWMStreetEditorViewController.mm +++ b/iphone/Maps/Classes/Editor/Street/MWMStreetEditorViewController.mm @@ -45,8 +45,9 @@ namespace - (void)configData { - m_streets = self.delegate.nearbyStreets; - auto const & currentStreet = self.delegate.currentStreet; + id delegate = self.delegate; + m_streets = delegate.nearbyStreets; + auto const & currentStreet = delegate.currentStreet; BOOL const haveCurrentStreet = !currentStreet.m_defaultName.empty(); if (haveCurrentStreet) @@ -88,10 +89,11 @@ namespace - (void)onDone { + id delegate = self.delegate; if (self.selectedStreet == NSNotFound) - [self.delegate setNearbyStreet:{m_editedStreetName, ""}]; + [delegate setNearbyStreet:{m_editedStreetName, ""}]; else - [self.delegate setNearbyStreet:m_streets[self.selectedStreet]]; + [delegate setNearbyStreet:m_streets[self.selectedStreet]]; [self onCancel]; } diff --git a/iphone/Maps/Classes/MWMBasePlacePageView.mm b/iphone/Maps/Classes/MWMBasePlacePageView.mm index 643ebcbe71..16e3b99c65 100644 --- a/iphone/Maps/Classes/MWMBasePlacePageView.mm +++ b/iphone/Maps/Classes/MWMBasePlacePageView.mm @@ -674,7 +674,7 @@ using namespace storage; default: { MWMPlacePageInfoCell * tCell = (MWMPlacePageInfoCell *)cell; - tCell.currentEntity = self.entity; + tCell.currentEntity = entity; [tCell configureWithType:cellType info:[entity getCellValue:cellType]]; break; } diff --git a/iphone/Maps/Classes/MWMPlacePage.mm b/iphone/Maps/Classes/MWMPlacePage.mm index 772906428c..baa1304972 100644 --- a/iphone/Maps/Classes/MWMPlacePage.mm +++ b/iphone/Maps/Classes/MWMPlacePage.mm @@ -54,17 +54,18 @@ extern NSString * const kPP2BookmarkEditingIPADSegue = @"PP2BookmarkEditingIPAD" - (void)configure { - MWMPlacePageEntity * entity = self.manager.entity; + MWMPlacePageViewManager * manager = self.manager; + MWMPlacePageEntity * entity = manager.entity; [self.basePlacePageView configureWithEntity:entity]; BOOL const isPrepareRouteMode = MapsAppDelegate.theApp.routingPlaneMode != MWMRoutingPlaneModeNone; if (self.actionBar.isPrepareRouteMode == isPrepareRouteMode) { - [self.actionBar configureWithPlacePageManager:self.manager]; + [self.actionBar configureWithPlacePageManager:manager]; } else { [self.actionBar removeFromSuperview]; - self.actionBar = [MWMPlacePageActionBar actionBarForPlacePageManager:self.manager]; + self.actionBar = [MWMPlacePageActionBar actionBarForPlacePageManager:manager]; } } @@ -128,8 +129,10 @@ extern NSString * const kPP2BookmarkEditingIPADSegue = @"PP2BookmarkEditingIPAD" - (void)editBookmark { - [self.manager.ownerViewController performSegueWithIdentifier:IPAD ? kPP2BookmarkEditingIPADSegue : - kPP2BookmarkEditingSegue sender:self.manager]; + MWMPlacePageViewManager * manager = self.manager; + [manager.ownerViewController + performSegueWithIdentifier:IPAD ? kPP2BookmarkEditingIPADSegue : kPP2BookmarkEditingSegue + sender:manager]; } - (void)reloadBookmark diff --git a/iphone/Maps/Classes/MWMPlacePageActionBar.mm b/iphone/Maps/Classes/MWMPlacePageActionBar.mm index 866949efbc..cf3184260b 100644 --- a/iphone/Maps/Classes/MWMPlacePageActionBar.mm +++ b/iphone/Maps/Classes/MWMPlacePageActionBar.mm @@ -171,20 +171,21 @@ NSString * const kPlacePageActionBarNibName = @"PlacePageActionBar"; - (void)tapOnButtonWithType:(EButton)type { + MWMPlacePageViewManager * placePageManager = self.placePageManager; switch (type) { - case EButton::Api: [self.placePageManager apiBack]; break; - case EButton::Booking: [self.placePageManager book:NO]; break; - case EButton::Call: [self.placePageManager call]; break; + case EButton::Api: [placePageManager apiBack]; break; + case EButton::Booking: [placePageManager book:NO]; break; + case EButton::Call: [placePageManager call]; break; case EButton::Bookmark: if (self.isBookmark) - [self.placePageManager removeBookmark]; + [placePageManager removeBookmark]; else - [self.placePageManager addBookmark]; + [placePageManager addBookmark]; break; - case EButton::RouteFrom: [self.placePageManager routeFrom]; break; - case EButton::RouteTo: [self.placePageManager routeTo]; break; - case EButton::Share: [self.placePageManager share]; break; + case EButton::RouteFrom: [placePageManager routeFrom]; break; + case EButton::RouteTo: [placePageManager routeTo]; break; + case EButton::Share: [placePageManager share]; break; case EButton::More: [self showActionSheet]; break; case EButton::Spacer: break; } diff --git a/iphone/Maps/Classes/MWMPlacePageButtonCell.mm b/iphone/Maps/Classes/MWMPlacePageButtonCell.mm index 0e856522be..5b0f81416a 100644 --- a/iphone/Maps/Classes/MWMPlacePageButtonCell.mm +++ b/iphone/Maps/Classes/MWMPlacePageButtonCell.mm @@ -24,12 +24,13 @@ - (IBAction)buttonTap { + MWMPlacePageViewManager * manager = self.manager; switch (self.type) { - case MWMPlacePageCellTypeEditButton: [self.manager editPlace]; break; - case MWMPlacePageCellTypeAddBusinessButton: [self.manager addBusiness]; break; - case MWMPlacePageCellTypeAddPlaceButton: [self.manager addPlace]; break; - case MWMPlacePageCellTypeBookingMore: [self.manager book:YES]; break; + case MWMPlacePageCellTypeEditButton: [manager editPlace]; break; + case MWMPlacePageCellTypeAddBusinessButton: [manager addBusiness]; break; + case MWMPlacePageCellTypeAddPlaceButton: [manager addPlace]; break; + case MWMPlacePageCellTypeBookingMore: [manager book:YES]; break; default: NSAssert(false, @"Incorrect cell type!"); break; } } diff --git a/iphone/Maps/Classes/MapDownloader/Cells/MWMMapDownloaderTableViewCell.mm b/iphone/Maps/Classes/MapDownloader/Cells/MWMMapDownloaderTableViewCell.mm index fa6112d52e..e685999a16 100644 --- a/iphone/Maps/Classes/MapDownloader/Cells/MWMMapDownloaderTableViewCell.mm +++ b/iphone/Maps/Classes/MapDownloader/Cells/MWMMapDownloaderTableViewCell.mm @@ -147,20 +147,21 @@ { storage::NodeAttrs nodeAttrs; GetFramework().GetStorage().GetNodeAttrs(m_countryId, nodeAttrs); + id delegate = self.delegate; switch (nodeAttrs.m_status) { case NodeStatus::NotDownloaded: case NodeStatus::Partly: if ([self isKindOfClass:[MWMMapDownloaderLargeCountryTableViewCell class]]) - [self.delegate openNodeSubtree:m_countryId]; + [delegate openNodeSubtree:m_countryId]; else - [self.delegate downloadNode:m_countryId]; + [delegate downloadNode:m_countryId]; break; case NodeStatus::Undefined: - case NodeStatus::Error: [self.delegate retryDownloadNode:m_countryId]; break; - case NodeStatus::OnDiskOutOfDate: [self.delegate updateNode:m_countryId]; break; + case NodeStatus::Error: [delegate retryDownloadNode:m_countryId]; break; + case NodeStatus::OnDiskOutOfDate: [delegate updateNode:m_countryId]; break; case NodeStatus::Downloading: - case NodeStatus::InQueue: [self.delegate cancelNode:m_countryId]; break; + case NodeStatus::InQueue: [delegate cancelNode:m_countryId]; break; case NodeStatus::OnDisk: break; } } diff --git a/iphone/Maps/Classes/MapDownloader/MWMBaseMapDownloaderViewController.mm b/iphone/Maps/Classes/MapDownloader/MWMBaseMapDownloaderViewController.mm index bc12b85b51..e28f151896 100644 --- a/iphone/Maps/Classes/MapDownloader/MWMBaseMapDownloaderViewController.mm +++ b/iphone/Maps/Classes/MapDownloader/MWMBaseMapDownloaderViewController.mm @@ -850,7 +850,7 @@ using namespace mwm; - (void)setTableView:(UITableView *)tableView { _tableView = tableView; - _tableView.tableFooterView = [[UIView alloc] initWithFrame:{}]; + tableView.tableFooterView = [[UIView alloc] initWithFrame:{}]; self.dataSource = self.defaultDataSource; } diff --git a/iphone/Maps/Classes/Search/MWMSearch.mm b/iphone/Maps/Classes/Search/MWMSearch.mm index b9292c3f62..8f4e5f7585 100644 --- a/iphone/Maps/Classes/Search/MWMSearch.mm +++ b/iphone/Maps/Classes/Search/MWMSearch.mm @@ -61,44 +61,52 @@ using TObservers = NSHashTable<__kindof TObserver>; { NSTimeInterval const timestamp = [NSDate date].timeIntervalSince1970; self.lastSearchTimestamp = timestamp; - __weak auto weakSelf = self; - m_everywhereParams.m_onResults = [weakSelf, timestamp](search::Results const & results) { - __strong auto self = weakSelf; - if (!self) - return; - if (timestamp != self.lastSearchTimestamp) - return; - if (results.IsEndMarker()) - { - self.everywhereSearchActive = NO; + { + __weak auto weakSelf = self; + m_everywhereParams.m_onResults = [weakSelf, timestamp](search::Results const & results) { + __strong auto self = weakSelf; + if (!self) + return; + if (timestamp != self.lastSearchTimestamp) + return; + if (results.IsEndMarker()) + { + self.everywhereSearchActive = NO; + [self onSearchCompleted]; + } + else + { + self->m_results = results; + self.suggestionsCount = results.GetSuggestsCount(); + [self onSearchResultsUpdated]; + } + }; + } + { + __weak auto weakSelf = self; + m_viewportParams.m_onStarted = [weakSelf] { + __strong auto self = weakSelf; + if (!self) + return; + if (IPAD) + { + GetFramework().SearchEverywhere(self->m_everywhereParams); + self.everywhereSearchActive = YES; + } + self.viewportSearchActive = YES; + [self onSearchStarted]; + }; + } + { + __weak auto weakSelf = self; + m_viewportParams.m_onCompleted = [weakSelf] { + __strong auto self = weakSelf; + if (!self) + return; + self.viewportSearchActive = NO; [self onSearchCompleted]; - } - else - { - self->m_results = results; - self.suggestionsCount = results.GetSuggestsCount(); - [self onSearchResultsUpdated]; - } - }; - m_viewportParams.m_onStarted = [weakSelf] { - __strong auto self = weakSelf; - if (!self) - return; - if (IPAD) - { - GetFramework().SearchEverywhere(self->m_everywhereParams); - self.everywhereSearchActive = YES; - } - self.viewportSearchActive = YES; - [self onSearchStarted]; - }; - m_viewportParams.m_onCompleted = [weakSelf] { - __strong auto self = weakSelf; - if (!self) - return; - self.viewportSearchActive = NO; - [self onSearchCompleted]; - }; + }; + } } - (void)update diff --git a/iphone/Maps/Classes/Widgets/MWMMapDownloadDialog.mm b/iphone/Maps/Classes/Widgets/MWMMapDownloadDialog.mm index 519a19eab1..f15d8c55d8 100644 --- a/iphone/Maps/Classes/Widgets/MWMMapDownloadDialog.mm +++ b/iphone/Maps/Classes/Widgets/MWMMapDownloadDialog.mm @@ -125,8 +125,9 @@ using namespace storage; case NodeStatus::NotDownloaded: case NodeStatus::Partly: { + MapViewController * controller = self.controller; BOOL const isMapVisible = - [self.controller.navigationController.topViewController isEqual:self.controller]; + [controller.navigationController.topViewController isEqual:controller]; if (isMapVisible && !self.isAutoDownloadCancelled && canAutoDownload(m_countryId)) { [Statistics logEvent:kStatDownloaderMapAction @@ -138,7 +139,7 @@ using namespace storage; }]; m_autoDownloadCountryId = m_countryId; [MWMStorage downloadNode:m_countryId - alertController:self.controller.alertController + alertController:controller.alertController onSuccess:^{ [self showInQueue]; }]; @@ -313,10 +314,11 @@ using namespace storage; - (IBAction)downloadAction { + MapViewController * controller = self.controller; if (platform::migrate::NeedMigrate()) { [Statistics logEvent:kStatDownloaderMigrationDialogue withParameters:@{kStatFrom : kStatMap}]; - [self.controller openMigration]; + [controller openMigration]; } else { @@ -328,7 +330,7 @@ using namespace storage; kStatScenario : kStatDownload }]; [MWMStorage downloadNode:m_countryId - alertController:self.controller.alertController + alertController:controller.alertController onSuccess:^{ [self showInQueue]; }]; diff --git a/iphone/Maps/MWMNightModeController.mm b/iphone/Maps/MWMNightModeController.mm index b389161f1f..0ffb6f81db 100644 --- a/iphone/Maps/MWMNightModeController.mm +++ b/iphone/Maps/MWMNightModeController.mm @@ -91,10 +91,12 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { - self.selectedCell.accessoryType = UITableViewCellAccessoryNone; - self.selectedCell = [tableView cellForRowAtIndexPath:indexPath]; - self.selectedCell.accessoryType = UITableViewCellAccessoryCheckmark; - self.selectedCell.selected = NO; + SelectableCell * selectedCell = self.selectedCell; + selectedCell.accessoryType = UITableViewCellAccessoryNone; + selectedCell = [tableView cellForRowAtIndexPath:indexPath]; + selectedCell.accessoryType = UITableViewCellAccessoryCheckmark; + selectedCell.selected = NO; + self.selectedCell = selectedCell; } @end diff --git a/iphone/Maps/MWMRecentTrackSettingsController.mm b/iphone/Maps/MWMRecentTrackSettingsController.mm index 956b29dade..3b0ec4a2f8 100644 --- a/iphone/Maps/MWMRecentTrackSettingsController.mm +++ b/iphone/Maps/MWMRecentTrackSettingsController.mm @@ -90,9 +90,11 @@ typedef NS_ENUM(NSUInteger, DurationInHours) { One = 1, Two = 2, Six = 6, Twelve - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { - self.selectedCell.accessoryType = UITableViewCellAccessoryNone; - self.selectedCell = [tableView cellForRowAtIndexPath:indexPath]; - self.selectedCell.selected = NO; + SelectableCell * selectedCell = self.selectedCell; + selectedCell.accessoryType = UITableViewCellAccessoryNone; + selectedCell = [tableView cellForRowAtIndexPath:indexPath]; + selectedCell.selected = NO; + self.selectedCell = selectedCell; } - (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section diff --git a/iphone/Maps/MWMUnitsController.mm b/iphone/Maps/MWMUnitsController.mm index 708dd1fd39..859b99e12c 100644 --- a/iphone/Maps/MWMUnitsController.mm +++ b/iphone/Maps/MWMUnitsController.mm @@ -27,13 +27,14 @@ - (void)setSelectedCell:(SelectableCell *)cell { - if ([_selectedCell isEqual:cell]) + SelectableCell * selectedCell = _selectedCell; + if (selectedCell == cell) return; - _selectedCell.accessoryType = UITableViewCellAccessoryNone; + selectedCell.accessoryType = UITableViewCellAccessoryNone; + cell.accessoryType = UITableViewCellAccessoryCheckmark; + cell.selected = NO; _selectedCell = cell; - _selectedCell.accessoryType = UITableViewCellAccessoryCheckmark; - _selectedCell.selected = NO; if (cell == self.kilometers) { [Statistics logEvent:kStatEventName(kStatSettings, kStatChangeMeasureUnits)