表滚动应用程序崩溃

时间:2016-11-22 13:25:36

标签: ios iphone swift2 tableviewcell

在滚动tableview上,我的应用程序崩溃并显示可选值不是nil。第一次,我的条件被执行并且对我来说很好,但是当我们滚动并且事件条件执行并且应用程序崩溃时。请看一下。我是ios的新手。任何帮助,将不胜感激。

  let identifier = "CustumCell"
            var cell: CustumCell! = tableView.dequeueReusableCellWithIdentifier(identifier) as? CustumCell
            if cell == nil {
                var nib:Array = NSBundle.mainBundle().loadNibNamed("CustumCell", owner: self, options: nil)
                if (myArray[indexPath.row]["type"] as? String == "event"){
                       cell = nib[5] as? CustumCell
                } else if (myArray[indexPath.row]["type"] as? String == "status"){
                    cell = nib[0] as? CustumCell

                }else if (myArray[indexPath.row]["type"] as? String == "tag"){
                    cell = nib[7] as? CustumCell
                }
                else {
                  cell = nib[8] as? CustumCell
                }




        if (myArray[indexPath.row]["type"] as? String == "event"){
                    print(myArray[indexPath.row]["profile_image"])
                    cell.homeEvent.sd_setImageWithURL(NSURL(string:myArray[indexPath.row]["profile_image"] as? String ?? ""))
                    cell.homeeventtitleName.text = myArray[indexPath.row]["related_name"] as? String ?? ""
                     cell.homeeventUsername.text = myArray[indexPath.row]["related_user_name"]! as? String ?? ""
                     cell.homeeventStatus.text = myArray[indexPath.row]["status"]! as? String ?? ""
                    let event = myArray[indexPath.row]["event"]! as? [[String:AnyObject]]
                    if (event?.count == 0){

                    } else {
                    let startDate = event![0]["start_date"] as? String ?? ""
                    let endDate = event![0]["start_month"] as? String ?? ""
                    cell.homeeventDate.text =  startDate + endDate
                     cell.homeeventfirst.text = event![0]["event_name"] as? String ?? ""
                    cell.homeeventsecond.text = event![0]["location"] as? String ?? ""
                    cell.homeeventthird.text = event![0]["start_time"] as? String ?? ""
                    }
                    cell.homeeventlastSeen.text = myArray[indexPath.row]["activity_date"] as? String ?? ""

                     cell.homeeventImage.sd_setImageWithURL(NSURL(string:  event![0]["image"] as? String ?? ""))
                     cell.likeLabel.text = myArray[indexPath.row]["like"] as? String ?? ""
                    cell.commentLabel.text = myArray[indexPath.row]["comment"] as? String ?? ""
                }

0 个答案:

没有答案