-1

well, with debuging in simulator app works fine but while run with device (iPhone) it show error like

unexpectedly found nil while unwrapping an Optional value

 case 8:
    var myview = UIView()
    myview.backgroundColor = UIColor.whiteColor()
    myview.layer.shadowOffset = CGSizeMake(1, 0);






    if indexPath.row == 0
    {
        myview.frame = (frame: CGRectMake(10, 0, 300, 30))

        let  titlelable:UILabel = UILabel(frame: CGRectMake(70, 5, 200, 20))
        //        let titlelable = self.mylable("Past Employers", sizeoflable: CGRectMake(100, 10, 150, 25), labelcolor: UIColor.blackColor(), labelfont: UIFont.systemFontOfSize(10), labeltextalinment: NSTextAlignment.Left)
        titlelable.text="  News & Press"
        titlelable.textColor = UIColor.blackColor()
        titlelable.font = UIFont.systemFontOfSize(20)
    //    titlelable.font = UIFont(name:"Source Sans Pro",size:20)
        titlelable.textAlignment = NSTextAlignment.Left
        myview .addSubview(titlelable)
        cell .addSubview(myview)

    }

    else if indexPath.row == 4
    {

        var imageVEml = UIImageView(frame:CGRectMake(120, 30, 24, 15 ))
        var imageEml : UIImage = UIImage(named:"view-all-icon2x")!
        imageVEml.image = imageEml
        myview .addSubview(imageVEml)


        let  TimeLabel:UILabel = UILabel(frame: CGRectMake(155, 13, 200, 50))
        //        let titlelable = self.mylable("Past Employers", sizeoflable: CGRectMake(100, 10, 150, 25), labelcolor: UIColor.blackColor(), labelfont: UIFont.systemFontOfSize(10), labeltextalinment: NSTextAlignment.Left)
        TimeLabel.text = "View all"
        TimeLabel.textColor = UIColor(red: 21.0/255,  green: 181.0/255, blue: 226.0/255, alpha: 1)
       TimeLabel.font = UIFont.systemFontOfSize(15)
     //    TimeLabel.font = UIFont(name:"Source Sans Pro",size:15)
        TimeLabel.textAlignment = NSTextAlignment.Left
        myview .addSubview(TimeLabel)


        cell.addSubview(myview)

    }
    else if indexPath.row == 1 || indexPath.row == 2 || indexPath.row == 3
    {
        println("indexpath#\(indexPath.row) ")
        //            cell.textLabel.text = NameArray[indexPath.row]as NSString
        //            cell.detailTextLabel?.text = DescArray [indexPath.row]as NSString
        myview.frame = (frame: CGRectMake(10, 0, 300, 100))
        let  titlelable:UILabel = UILabel(frame: CGRectMake(10, 3, 300, 80))
        //        let titlelable = self.mylable("Past Employers", sizeoflable: CGRectMake(100, 10, 150, 25), labelcolor: UIColor.blackColor(), labelfont: UIFont.systemFontOfSize(10), labeltextalinment: NSTextAlignment.Left)



        titlelable.text  = newsTitlearray[indexPath.row] as NSString
        titlelable.textColor = UIColor.blackColor()
        titlelable.numberOfLines = 0
        titlelable.font = UIFont.systemFontOfSize(18)
   //      titlelable.font = UIFont(name:"Source Sans Pro",size:18)
        titlelable.textAlignment = NSTextAlignment.Left
        myview .addSubview(titlelable )

        let  TimeLabel:UILabel = UILabel(frame: CGRectMake(130, titlelable.frame.size.height, 200, 25))
        //        let titlelable = self.mylable("Past Employers", sizeoflable: CGRectMake(100, 10, 150, 25), labelcolor: UIColor.blackColor(), labelfont: UIFont.systemFontOfSize(10), labeltextalinment: NSTextAlignment.Left)


        TimeLabel.text = newsTimearray[indexPath.row] as NSString
        TimeLabel.textColor = UIColor.grayColor()
        TimeLabel.font = UIFont.systemFontOfSize(15)
     //    TimeLabel.font = UIFont(name:"Source Sans Pro",size:15)
        TimeLabel.textAlignment = NSTextAlignment.Left
        myview .addSubview(TimeLabel)

        var imageVEml2 = UIImageView(frame:CGRectMake(115, titlelable.frame.size.height+7, 10, 10 ))
        var imageEml2 : UIImage = UIImage(named:"Dot2")!
        imageVEml2.image = imageEml2
        myview .addSubview(imageVEml2)


        let  Desclable:UILabel = UILabel(frame: CGRectMake(30, titlelable.frame.size.height, 100, 25))

        Desclable.text = (newslogolbl[indexPath.row] as NSString)
        Desclable.textColor = UIColor.grayColor()
        Desclable.numberOfLines = 0
        Desclable.font = UIFont.systemFontOfSize(15)
   //      Desclable.font = UIFont(name:"Source Sans Pro",size:15)
        Desclable.textAlignment = NSTextAlignment.Left
        myview .addSubview(Desclable)

        var imageVEml = UIImageView(frame:CGRectMake(10, titlelable.frame.size.height+5, 15, 15 ))
        var imageEml : UIImage = UIImage(named:companyLogo [indexPath.row] as NSString)!
        imageVEml.image = imageEml
        myview .addSubview(imageVEml)



        cell.addSubview(myview)


              }


    break

same question - "fatal error: unexpectedly found nil while unwrapping an Optional value when navigating" logs:

indexpath#2 indexpath#3 indexpath#1

fatal error: unexpectedly found nil while unwrapping an Optional value

bLacK hoLE
  • 781
  • 1
  • 7
  • 20
  • 1
    You should give more info, such as where that happens, some more crash logs, etc. Without that it's impossible to figure out what's going on. – Antonio Nov 18 '14 at 22:15
  • hey @Antonio i edited the ans will you please help me now – bLacK hoLE Nov 18 '14 at 22:23
  • Do you have a line of code where the error occurs? If not, can you set a breakpoint and step into the code to figure that out? – Antonio Nov 18 '14 at 22:26
  • Desclable.text = (newslogolbl[indexPath.row] as NSString) - in this line error occurs – bLacK hoLE Nov 18 '14 at 22:31
  • Ok - you should report that in the question, for clarity – Antonio Nov 18 '14 at 22:35
  • Also show the code where `newslogolbl` is defined – Antonio Nov 18 '14 at 22:36
  • Possible duplicate of [What does "fatal error: unexpectedly found nil while unwrapping an Optional value" mean?](https://stackoverflow.com/questions/32170456/what-does-fatal-error-unexpectedly-found-nil-while-unwrapping-an-optional-valu) – Cristik Mar 19 '18 at 06:03

1 Answers1

0

MANY things can cause nil to be found upon unwrapping, if you don't understand optionals, I would highly recommend reading up on them in the documentation.

As far as I can tell, you are using at least 3 optionals that you implicitly unwrapped (this can be seen by the ! after certain variables) and they all follow a "UIImage"

I'm assuming that this error might be caused by the fact that UIImage "Dot2" (or one of the other images) does not exist in the project, or is named incorrectly.

If thats not the case than you really need to add some breakpoints and try to isolate what line of code this error is occurring, as said MANY things can cause an optional to find nil.

EDIT:

newsloglbl is finding nil when you try to access the object at "indexPath", it seems your indexPath is probably bigger than the size of newsloglbl so it is finding nothing when trying to access an object at that path and failing. Please provide some code from newloglbl if you want more detailed help

Unome
  • 6,750
  • 7
  • 45
  • 87