У меня есть точки останова в обоих методах.cellForRowAtIndexPath
всегда вызывается перед heightForRowAtIndexPath
.Проблема в том, что у меня есть логический код в cellForRowAtIndexPath
, который зависит от высоты строки.В настоящее время высота строки, которую я получаю внутри cellForRowAtIndexPath
, всегда равна 0.
Есть ли способ разрешить вызову heightForRowAtIndexPath
до cellForRowAtIndexPath
?Если нет, то как явно вызвать heightForRowAtIndexPatch
в моем коде?
РЕДАКТИРОВАТЬ:
Вот мой код для cellForRowAtIndexPath
:
let slideshowCell = tableView.dequeueReusableCell(withIdentifier: "SlideShowCell") as! SlideShowTableViewCell
slideshowCell.delegate = self
slideshowCell.news = featuredNews
return slideshowCell
и вот мойкод для heightForRowAtIndexPatch
:
let filterApplied = categoryNews.count != filteredCategoryNews.count
if featuredNews.count == 0 || filterApplied
{
return 0
}
else
{
return 530
}
и когда я устанавливаю featuredNews
в slideshowCell.news
, я запускаю этот метод в наблюдателе свойства slideshowCell.news
s didSet
:
private func populateSlideshowScrollView()
{
let imagesCount = CGFloat(slideshowNews.count)
// set the scrollView's content size to the size of all the images
scrollView.contentSize = CGSize(width: scrollView.frame.width * imagesCount, height: scrollView.frame.height)
// Remove subviews of ScrollView before populating it with new images
for subview in scrollView.subviews
{
subview.removeFromSuperview()
}
// populate the scrollView with images form the 'slideshowNews' property
for i in 0..<slideshowNews.count
{
let imgView = UIImageView(frame: CGRect(x: scrollView.frame.width * CGFloat(i),
y: scrollView.bounds.origin.y,
width: scrollView.frame.width,
height: scrollView.frame.height))
imgView.contentMode = .scaleAspectFill
imgView.clipsToBounds = true
imgView.image = slideshowNews[i].image
scrollView.addSubview(imgView)
}
// set scrollview to the first page from the right, only the first two times this method called.
// After that the current page of page control should be in the correct position
if numberOfRefresh < 2
{
scrollView.setContentOffset(CGPoint(x: scrollView.frame.width * (imagesCount - 1), y: 0), animated: false)
newsTitleLabel.text = slideshowNews.last?.title
sourceLabel.text = slideshowNews.last?.source.name
numberOfRefresh += 1
}
scrollToPage(page: pageControl.currentPage, animated: false) // to update scrollView's contentOffset
}
Проблема в том, что scrollView.frame.height
всегда будет возвращать ноль, потому что heightForRowAtIndexPath
еще не вызывается в этой точке.