0
Swift iOS
xcode 7.1 Beta

I am trying to set background image on the PFQueryTableViewController. I tried dragging the table from the story board (Ref. outlet: tableView) but I am not able to make the code work referring to that outlet.

    let image = UIImage(named: "Background")
    tableView.backgroundView = UIImageView(image: image)

The app crashes stating:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle:.

I even tried setting the background color tableView.backgroundColor = UIColor.greenColor()

But again, the app crashes

Can someone explain what's going on in here? I searched online, but most of the posts are only related to fetching images inside the PFQueryTableViewController cell.

Vicky Arora
  • 501
  • 2
  • 7
  • 20

1 Answers1

1

Try using the same code inside the queryForTable() block that returns query. It should work. No need of reference outlet.

Code should be something like:

override func queryForTable() -> PFQuery {

  let image = UIImage(named: "YourImageName")
  tableView.backgroundView = UIImageView(image: image)

  // your PFQueryTableViewController query goes here.... 

  return query
}
NS1518
  • 838
  • 1
  • 8
  • 23
  • Exactly what I needed. Thanks – Vicky Arora Oct 24 '15 at 23:49
  • wait what why set it in the `queryForTable`?? the error you're getting is because it can't load the nib file. How did this code fix your problem? – hhanesand Oct 25 '15 at 00:08
  • @lightice11 Do you have a better solution? Or anything wrong in this solution? Please elaborate. To your question, I have not added any nib file myself. I am using PFQueryTableViewController. Loading data inside that using Parse query. – Vicky Arora Oct 25 '15 at 00:13
  • @VickyArora could you post some more of your view controller code? – hhanesand Oct 25 '15 at 00:14