EXC_BAD_ACCESS KERN_INVALID_ADDRESS 在 Swift 和 iPhone 5
EXC_BAD_ACCESS KERN_INVALID_ADDRESS in Swift and iPhone 5
我刚刚启动了该应用程序,iPhone 5 和 5c 以及 iOS 10.3.3(仅限)出现问题。
我真的不明白这个问题,即使有 Crashlytics 报告:
问题似乎出在这一行:
@objc UserProfilViewController.collectionView(UICollectionView, layout : UICollectionViewLayout, sizeForItemAtIndexPath : IndexPath) -> CGSize
这是我的代码:
// Cell size
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: IndexPath) -> CGSize {
let size: CGSize
if cellIsNull == false {
size = CGSize(width: self.view.frame.size.width * 0.47, height: self.view.frame.size.width * 0.47)
} else {
size = CGSize(width: self.view.frame.size.width, height: self.view.frame.size.width * 0.47)
}
return size
}
如果我 运行 模拟器上的应用程序(带有 iPhone 5),应用程序不会崩溃,而且我没有 iPhone 5 所以我不测试一下。
称之为巧合。几个小时前我问了一个 问题。不一样但相似。
解决方法是在函数定义前加上@objc
。所以功能应该是这样的:
@objc func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: IndexPath) -> CGSize {
....
}
需要注意的主要事情是崩溃是随机的。我自己还没有收到这个。它可能有可能依赖于 iOS 或间接依赖于 Swift 版本。
我刚刚启动了该应用程序,iPhone 5 和 5c 以及 iOS 10.3.3(仅限)出现问题。
我真的不明白这个问题,即使有 Crashlytics 报告:
问题似乎出在这一行:
@objc UserProfilViewController.collectionView(UICollectionView, layout : UICollectionViewLayout, sizeForItemAtIndexPath : IndexPath) -> CGSize
这是我的代码:
// Cell size
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: IndexPath) -> CGSize {
let size: CGSize
if cellIsNull == false {
size = CGSize(width: self.view.frame.size.width * 0.47, height: self.view.frame.size.width * 0.47)
} else {
size = CGSize(width: self.view.frame.size.width, height: self.view.frame.size.width * 0.47)
}
return size
}
如果我 运行 模拟器上的应用程序(带有 iPhone 5),应用程序不会崩溃,而且我没有 iPhone 5 所以我不测试一下。
称之为巧合。几个小时前我问了一个
解决方法是在函数定义前加上@objc
。所以功能应该是这样的:
@objc func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: IndexPath) -> CGSize {
....
}
需要注意的主要事情是崩溃是随机的。我自己还没有收到这个。它可能有可能依赖于 iOS 或间接依赖于 Swift 版本。