Swift,EXC_BAD_Instruction

时间:2017-06-12 10:43:17

标签: ios arrays swift wrapping

我的程序应该从数组中获取数据,并将其放在tableView

 var rideTime: String!
    var rideLocation: String!
    var RideDriver: String!

    rideTime = RidestList[indexPath.row].TimeX!
    rideLocation = RidestList[indexPath.row].LocationX!
    RideDriver = RidestList[indexPath.row].DriverNameX!


    cell.DriverX.text = rideTime;
    cell.TimeX.text = rideLocation;
    cell.LocationX.text = RideDriver;

    return cell

在cell.DriverX.text = rideTime中,它给了我EXC_BAD_Instraction

并且出现“错误:在展开Optional值时意外发现nil (lldb)“出现错误,有人可以帮忙吗?

2 个答案:

答案 0 :(得分:0)

    if let ride_time = RidestList[indexPath.row].TimeX
    {
       cell.DriverX.text = ride_time
    } 

 if let ride_location =RidestList[indexPath.row].LocationX 
    {

       cell.TimeX.text = ride_location
}

 if let river_driver =RidestList[indexPath.row].DriverNameX
    {

       cell.LocationX.text = river_driver
}

这可以帮助您解决问题

答案 1 :(得分:0)

崩溃基本上是由于您的变量 rideTime 没有值。最佳实践是使用可选的绑定 var rideTime:String?到可以预期空值的变量。这将限制您面临的崩溃。