diff options
author | Ilya Grechuhin <i.grechuhin@gmail.com> | 2017-07-21 15:27:40 +0300 |
---|---|---|
committer | Vlad Mihaylenko <vxmihaylenko@gmail.com> | 2017-07-21 16:33:55 +0300 |
commit | df15bfc581ff1ec68e41d9e156533a427146b114 (patch) | |
tree | 86007953c9e2e075e5932b9148bec371ee1f0e90 | |
parent | fb5055b48d12706e40886dad6a5dc5b71c9dc027 (diff) |
[FABRIC-8541] [ios] Fixed crash.push
-rw-r--r-- | iphone/Maps/UI/PlacePage/PlacePageLayout/MWMPlacePageLayout.mm | 61 |
1 files 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<MetainfoRows, Class> const kMetaInfoCells = { @property(nonatomic) MWMPPPreviewLayoutHelper * previewLayoutHelper; @property(nonatomic) MWMOpeningHoursLayoutHelper * openingHoursLayoutHelper; -@property(nonatomic) NSArray<NSIndexPath *> * buttonsSectionIndexPaths; @property(weak, nonatomic) MWMPlacePageTaxiCell * taxiCell; @property(weak, nonatomic) MWMPPViatorCarouselCell * viatorCell; +@property(nonatomic) BOOL buttonsSectionEnabled; + @end @implementation MWMPlacePageLayout @@ -113,7 +114,7 @@ map<MetainfoRows, Class> 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<MetainfoRows, Class> 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<MWMPlacePageButtonCell *>([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<MWMPlacePageButtonCell *>(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<MetainfoRows, Class> const kMetaInfoCells = { return _actionBar; } -- (NSArray<NSIndexPath *> *)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<NSIndexPath *> * 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]; |