gpt4 book ai didi

swift 错误 : Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, 子代码 = 0x0)

转载 作者:可可西里 更新时间:2023-11-01 02:18:09 26 4
gpt4 key购买 nike

当我尝试启动我的应用程序时,出现两个看起来像是内部断点的错误,但我无法删除它们,错误消息是:Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0) 这些是接收错误的代码行(如果需要我可以提供整个 View Controller ):

Interest(title: "We Love Traveling Around the World", description: "We love backpack and adventures! We walked to Antartica yesterday, and camped with some cute pinguines, and talked about this wonderful app idea. 🐧⛺️✨", featuredImage: UIImage(named: "r1")!),

private var interests = Interest.createInterests()

编辑:兴趣代码:

import UIKit

class HomeViewController: UIViewController
{
// MARK: - IBOutlets

@IBOutlet weak var backgroundImageView: UIImageView!
@IBOutlet weak var collectionView: UICollectionView!

@IBOutlet weak var currentUserProfileImageButton: UIButton!
@IBOutlet weak var currentUserFullNameButton: UIButton!

// MARK: - UICollectionViewDataSource
private var interests = Interest.createInterests()

override func preferredStatusBarStyle() -> UIStatusBarStyle {
return .LightContent
}

override func viewDidLoad() {
super.viewDidLoad()

// Do any additional setup after loading the view.
}

private struct Storyboard {
static let CellIdentifier = "Interest Cell"
}
}

extension HomeViewController : UICollectionViewDataSource
{
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 1
}

func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
{
return interests.count
}

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell
{
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(Storyboard.CellIdentifier, forIndexPath: indexPath) as! InterestCollectionViewCell

cell.interest = self.interests[indexPath.item]

return cell
}
}

extension HomeViewController : UIScrollViewDelegate
{
func scrollViewWillEndDragging(scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>)
{
let layout = self.collectionView?.collectionViewLayout as! UICollectionViewFlowLayout
let cellWidthIncludingSpacing = layout.itemSize.width + layout.minimumLineSpacing

var offset = targetContentOffset.memory
let index = (offset.x + scrollView.contentInset.left) / cellWidthIncludingSpacing
let roundedIndex = round(index)

offset = CGPoint(x: roundedIndex * cellWidthIncludingSpacing - scrollView.contentInset.left, y: -scrollView.contentInset.top)
targetContentOffset.memory = offset
}
}

最佳答案

您似乎没有名称为 r1 的图片。当您尝试使用 UIImage(named: "r1")! 展开它时,应用会崩溃。在将对象 UIImage 传递给 Interest

init 之前,尝试检查对象是否已创建

关于 swift 错误 : Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, 子代码 = 0x0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34586522/

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