gpt4 book ai didi

ios - 仅在 iPhone 4S 上在 postNotification 后添加观察者

转载 作者:行者123 更新时间:2023-11-30 13:29:11 25 4
gpt4 key购买 nike

我有一个功能齐全的代码,可以在适用于 iPhone >5 和所有 iPad 的 iOS >8.0 上完美运行,我通过观察者/通知传递信息和调用功能,但在 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()
}
}

观察:我在同一 View 中使用多个 Collection View ,并且 nib 文件命名正确

在通知发布后,iPhone 4S 是否会加载 viewDidLoad 方法,有什么原因吗?

最佳答案

设法解决我的问题。 iphone 4s 屏幕尺寸不够大,无法触发 cellForIndex 事件,并且直到手机屏幕向下滚动后才会启动类/观察者。

关于ios - 仅在 iPhone 4S 上在 postNotification 后添加观察者,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36777885/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com