From df15bfc581ff1ec68e41d9e156533a427146b114 Mon Sep 17 00:00:00 2001 From: Ilya Grechuhin Date: Fri, 21 Jul 2017 15:27:40 +0300 Subject: [FABRIC-8541] [ios] Fixed crash. --- .../PlacePageLayout/MWMPlacePageLayout.mm | 61 ++++++++++++---------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/iphone/Maps/UI/PlacePage/PlacePageLayout/MWMPlacePageLayout.mm b/iphone/Maps/UI/PlacePage/PlacePageLayout/MWMPlacePageLayout.mm index d08b030259..c8f050095e 100644 --- a/iphone/Maps/UI/PlacePage/PlacePageLayout/MWMPlacePageLayout.mm +++ b/iphone/Maps/UI/PlacePage/PlacePageLayout/MWMPlacePageLayout.mm @@ -57,11 +57,12 @@ map const kMetaInfoCells = { @property(nonatomic) MWMPPPreviewLayoutHelper * previewLayoutHelper; @property(nonatomic) MWMOpeningHoursLayoutHelper * openingHoursLayoutHelper; -@property(nonatomic) NSArray * buttonsSectionIndexPaths; @property(weak, nonatomic) MWMPlacePageTaxiCell * taxiCell; @property(weak, nonatomic) MWMPPViatorCarouselCell * viatorCell; +@property(nonatomic) BOOL buttonsSectionEnabled; + @end @implementation MWMPlacePageLayout @@ -113,7 +114,7 @@ map const kMetaInfoCells = { - (UIView *)shareAnchor { return self.actionBar.shareAnchor; } - (void)showWithData:(MWMPlacePageData *)data { - self.buttonsSectionIndexPaths = nil; + self.buttonsSectionEnabled = YES; self.data = data; data.sectionsAreReadyCallback = ^(NSRange const & range, MWMPlacePageData * d) { @@ -164,14 +165,37 @@ map const kMetaInfoCells = { [self.previewLayoutHelper setSpeedAndAltitude:speedAndAltitude]; } -- (void)setButtonsSectionEnabled:(BOOL)isEnabled +- (void)setButtonsSectionEnabled:(BOOL)buttonsSectionEnabled { - [self.buttonsSectionIndexPaths enumerateObjectsUsingBlock:^(NSIndexPath * obj, NSUInteger idx, BOOL * stop) { - auto c = static_cast([self.placePageView.tableView cellForRowAtIndexPath:obj]); + if (_buttonsSectionEnabled == buttonsSectionEnabled) + return; + auto data = self.data; + auto tv = self.placePageView.tableView; + if (!data || !tv) + return; + + _buttonsSectionEnabled = buttonsSectionEnabled; + auto const & sections = data.sections; + auto const it = find(sections.begin(), sections.end(), place_page::Sections::Buttons); + if (it == sections.end()) + return; + NSInteger const sectionNumber = distance(sections.begin(), it); + auto const numberOfRows = [tv numberOfRowsInSection:sectionNumber]; + for (NSInteger i = 0; i < numberOfRows; ++i) + { + auto ip = [NSIndexPath indexPathForRow:i inSection:sectionNumber]; + auto c = [tv cellForRowAtIndexPath:ip]; + BOOL const isKindOfMWMPlacePageButtonCell = [c isKindOfClass:[MWMPlacePageButtonCell class]]; + NSAssert(isKindOfMWMPlacePageButtonCell, @"Invalid cell class"); + if (!isKindOfMWMPlacePageButtonCell) + continue; + auto cell = static_cast(c); // Hotel description button is always enabled. - if (c.rowType != place_page::ButtonsRows::HotelDescription) - c.enabled = isEnabled; - }]; + if (cell.rowType == place_page::ButtonsRows::HotelDescription) + cell.enabled = YES; + else + cell.enabled = buttonsSectionEnabled; + } } - (MWMPlacePageActionBar *)actionBar @@ -184,27 +208,6 @@ map const kMetaInfoCells = { return _actionBar; } -- (NSArray *)buttonsSectionIndexPaths -{ - if (!_buttonsSectionIndexPaths) - { - auto const & sections = self.data.sections; - auto tv = self.placePageView.tableView; - - auto const it = find(sections.begin(), sections.end(), place_page::Sections::Buttons); - NSMutableArray * ip = @[].mutableCopy; - if (it != sections.end()) - { - NSInteger const sectionNumber = distance(sections.begin(), it); - auto const numberOfRows = [tv numberOfRowsInSection:sectionNumber]; - for (NSInteger i = 0; i < numberOfRows; i++) - [ip addObject:[NSIndexPath indexPathForRow:i inSection:sectionNumber]]; - } - _buttonsSectionIndexPaths = ip.copy; - } - return _buttonsSectionIndexPaths; -} - - (void)close { [self.layoutImpl onClose]; -- cgit v1.2.3