From 068dd8b86873a32cffa5763ebfb0256a3d24896d Mon Sep 17 00:00:00 2001 From: Panayot Cankov Date: Tue, 2 Jun 2015 10:47:40 +0300 Subject: [PATCH] Fixed crash due to asserts in scrollToRowAtIndexPathAtScrollPositionAnimated for ListView's UITableView instance. Fixed a case where the UITableView fails to calculate its layout when the page it is displayed in is navigated to, from and back to. --- ui/list-view/list-view.ios.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/ui/list-view/list-view.ios.ts b/ui/list-view/list-view.ios.ts index 10bcf5201..779d33cef 100644 --- a/ui/list-view/list-view.ios.ts +++ b/ui/list-view/list-view.ios.ts @@ -99,23 +99,22 @@ class UITableViewDelegateImpl extends NSObject implements UITableViewDelegate { } public tableViewHeightForRowAtIndexPath(tableView: UITableView, indexPath: NSIndexPath): number { - if (utils.ios.MajorVersion < 8) { - // in iOS 7.1 this method is called before tableViewCellForRowAtIndexPath so we need fake cell to measure its content. + var height = undefined; + if (utils.ios.MajorVersion >= 8) { + height = this._owner.getHeight(indexPath.row); + } + if (utils.ios.MajorVersion < 8 || height === undefined) { + // in iOS 7.1 (or iOS8+ after call to scrollToRowAtIndexPath:atScrollPosition:animated:) this method is called before tableViewCellForRowAtIndexPath so we need fake cell to measure its content. var cell = this._measureCell; if (!cell) { this._measureCell = tableView.dequeueReusableCellWithIdentifier(CELLIDENTIFIER) || ListViewCell.new(); cell = this._measureCell; } - return this._owner._prepareCell(cell, indexPath); + height = this._owner._prepareCell(cell, indexPath); } - return this._owner.getHeight(indexPath.row); - } - - public tableViewEstimatedHeightForRowAtIndexPath(tableView: UITableView, indexPath: NSIndexPath): number { - // TODO: Consider exposing such property on ListView. - return DEFAULT_HEIGHT; + return height; } } @@ -148,6 +147,7 @@ export class ListView extends common.ListView { this._ios.registerClassForCellReuseIdentifier(ListViewCell.class(), CELLIDENTIFIER); this._ios.autoresizesSubviews = false; this._ios.autoresizingMask = UIViewAutoresizing.UIViewAutoresizingNone; + this._ios.estimatedRowHeight = DEFAULT_HEIGHT; var dataSource = DataSource.new().initWithOwner(this);