Наблюдатель добавляется только после postNotification на iPhone 4S
У меня есть полностью функциональный код, который отлично работает на iOS >8.0 для iPhone>5 и на всех iPad, где я передаю информацию и функцию вызова через Observers/Notifications, но на iPhone 4S он просто не работает.
В процессе отладки я обнаружил, что ТОЛЬКО во время работы на iPhone 4S добавляется наблюдатель ПОСЛЕ уведомления.
Это происходит на устройствах и на симуляторе, на iOS 8 и 9 соответственно.
Код:
**PostNotification**
override func viewDidLoad() {
super.viewDidLoad()
self.registerCells()
UIApplication.sharedApplication().statusBarStyle = .LightContent
self.collectionView.delaysContentTouches = false
NSNotificationCenter.defaultCenter().addObserver(self, selector: "footerUpdateContentSize:", name: "footerUpdateContentSize", object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "seasonUpdateContentSize:", name: "seasonUpdateContentSize", object: nil)
self.loadDetailTVShow()
}
func registerCells()
{
self.collectionView.registerClass(HeaderDetailSeriesCell.self, forCellWithReuseIdentifier: "HeaderDetailSeriesCell")
self.collectionView.registerClass(FooterDetailSeriesCell.self, forCellWithReuseIdentifier: "FooterDetailSeriesCell")
self.collectionView.registerClass(SeriesSeasonContentCell.self, forCellWithReuseIdentifier: "SeriesSeasonContentCell")
}
func loadDetailTVShow()
{
let id: String! = (tvShow != nil) ? tvShow!.id! : episode!.seriesId!
ContentsClient().getContentById(id!).then { data -> Void in
let m: TVShow? = data as! TVShow?
self.tvShow = m!
self.collectionView.reloadData()
NSNotificationCenter.defaultCenter().postNotificationName("loadedTvShowlist", object: self.tvShow)
UIView.animateWithDuration(1.0, delay: 0, options: .TransitionNone, animations:
{
self.loadingView.alpha = 0.0
}, completion:nil)
}
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell
{
cell = collectionView.dequeueReusableCellWithReuseIdentifier("SeriesSeasonContentCell", forIndexPath: indexPath)
let seriesContent = cell as! SeriesSeasonContentCell
seriesContent.seriesContentCell?.tvShow = self.tvShow
seriesContent.contentView.frame = CGRect(x: 0.0, y: 0.0, width: width, height: heightSeason)
seriesContent.seriesContentCell?.view.frame = seriesContent.contentView.frame
}
**Observer**
class SeriesSeasonContent
override func viewDidLoad() {
super.viewDidLoad()
self.registerCells()
seasonSelectedIndex = 0
collectionView.reloadData()
NSNotificationCenter.defaultCenter().addObserver(self, selector: "loadedTvShowlist:", name: "loadedTvShowlist", object: nil)
}
func registerCells ()
{
self.seasonCollection.registerClass(SeasonViewCell.self, forCellWithReuseIdentifier: "SeasonViewCell")
self.collectionView.registerClass(EpisodeViewCell.self, forCellWithReuseIdentifier: "EpisodeViewCell")
}
func loadedTvShowlist(notification : NSNotification){
self.tvShow = notification.object! as? TVShow
if (tvShow?.seasons != nil && tvShow?.seasons?.count > 0)
{
self.currentSeason = ((tvShow?.seasons!.objectAtIndex(seasonSelectedIndex) as? Season)?.episodes)!
self.collectionView.reloadData()
self.seasonCollection.reloadData()
}
}
Obs: Я использую несколько представлений коллекций в одном представлении, и файлы перьев названы правильно
Есть ли какая-либо причина, по которой iPhone 4S загружает метод viewDidLoad после публикации уведомления?
1 ответ
Удалось решить мою проблему. Размер экрана iphone 4s не был достаточно большим, чтобы вызвать событие cellForIndex, и класс / наблюдатель не был инициирован, пока экран телефона не прокрутился вниз.