Xcode 当试图在表视图上显示数组中的图像时,我收到一个错误消息“quot;exc_bad_指令(代码=exc_I386_INVOP,子代码=0x0";

Xcode 当试图在表视图上显示数组中的图像时,我收到一个错误消息“quot;exc_bad_指令(代码=exc_I386_INVOP,子代码=0x0";,xcode,swift,tableview,Xcode,Swift,Tableview,要创建应用程序的“事件”页面,我使用表视图列出事件的图像、名称和详细信息。您可以选择事件,也可以添加事件 我当前正在使用存储为数组的数据填充表,但是当我尝试放置图像数据时,我在这行代码中返回一个错误: cell.photo.image = images[indexPath.row] 有人能帮我找出我返回此错误的原因吗 import UIKit class ViewController: UIViewController, UITableViewDataSource, UITa

要创建应用程序的“事件”页面,我使用表视图列出事件的图像、名称和详细信息。您可以选择事件,也可以添加事件

我当前正在使用存储为数组的数据填充表,但是当我尝试放置图像数据时,我在这行代码中返回一个错误:

cell.photo.image = images[indexPath.row]
有人能帮我找出我返回此错误的原因吗

    import UIKit

    class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

    @IBOutlet var tableView: UITableView!

    var names = ["BTown Diner", "Dunnkirk", "Chocolate Mousse", "Lil Wayne", "Annie", "Campus Squad Social"]
    var details = ["Free drink with meal after 12 AM", "LADIES drink free", "10% off all ice cream!", "Lil 500 concert", "an IU Theater Production", "Bring your Squad to the Campus Squad Social"]
    var images = [UIImage(named: "btown_diner"), UIImage(named: "dunnkirk"), UIImage(named: "choco_moose"), UIImage(named: "lilwayne"), UIImage(named: " ")]

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return names.count
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = self.tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! CustomCell

        cell.name.text = names[indexPath.row]
        cell.detail.text = details[indexPath.row]
        cell.photo.image = images[indexPath.row]

        return cell
    }


}
此外,这是我的CustomCell.swift文件

import UIKit

class CustomCell: UITableViewCell {

    @IBOutlet var photo: UIImageView!
    @IBOutlet var name: UILabel!
    @IBOutlet var detail: UILabel!

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(selected: Bool, animated: Bool) {
    super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
}

变量
names
的计数为6

您的表将有6行来自
返回名称。count
。但是,您的变量
images
的计数为5

我认为,当调用函数
tableView:cellforrowatinexpath
时,如果
indexPath
等于5,则图像数组超出了范围