swift - Thread 1 EXC error -


i've been creating firebase database have 1 error can't past. says:

thread 1 exc_bad_instruction (code=exc_i386_invop subcode=0x0)'

it's simple i'm looking past. ideas?

here's code & error on line of code:

// //  database.swift //  intern // //  created lani  daniels on 8/20/17. //  copyright © 2017 lani  daniels. rights reserved. //  import uikit import firebase import firebasedatabase  struct poststruct {     let title: string     let message: string }  class databaseviewcontroller: uitableviewcontroller {     var posts: [poststruct] = []      override func tableview(_ tableview: uitableview, cellforrowat indexpath: indexpath) -> uitableviewcell {          let cell = tableview.dequeuereusablecell(withidentifier: "cell", for: indexpath)          let label1 = cell.viewwithtag(1)as! uilabel         label1.text=posts[indexpath.row].title 

// error below:thread 1 exc_bad_instruction (code=exc_i386_invop subcode=0x0) let label2 = cell.viewwithtag(2)as! uilabel label2.text=posts[indexpath.row].message

        return cell     } } 

for first error:

let cell = tableview.dequeuereusablecell(withidentifier: "cell", for: indexpath) 

change tableview tableview

for second one: seems you're trying access outlet might not uilabel. check making optional biding like:

let label2 = cell.viewwithtag(2) as? uilabel  

and check label using breakpoint. might nil.

also better use custom cell class 2 labels outlets , dequeue custom cell in cellforrowat method:

class customcell: uitableviewcell {         @iboutlet weak var firstlabel: uilabel!         @iboutlet weak var secondlabel: uilabel! } 

and then

override func tableview(_ tableview: uitableview, cellforrowat indexpath: indexpath) -> uitableviewcell {          let cell = tableview.dequeuereusablecell(withidentifier: "cell", for: indexpath) as? customcell          cell?.firstlabel.text=posts[indexpath.row].title         cell?.secondlabel.text=posts[indexpath.row].message      return cell! } 

and don't forget set custom class cell in interface builder


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -