Giter Site home page Giter Site logo

Comments (15)

ethanneff avatar ethanneff commented on May 23, 2024 4

missing self.clientTable.reloadData() after self.messages.removeAll()

  override func viewDidAppear(animated: Bool) {
    self.messages.removeAll()
    self.clientTable.reloadData()
    // Listen for new messages in the Firebase database
    _refHandle = self.ref.child("messages").observeEventType(.ChildAdded, withBlock: { (snapshot) -> Void in
      self.messages.append(snapshot)
      let indexPath = NSIndexPath(forRow: self.messages.count-1, inSection: 0)
      self.clientTable.insertRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic)
      self.clientTable.scrollToRowAtIndexPath(indexPath, atScrollPosition: .Bottom, animated: true)
    })
  }

from codelab-friendlychat-web.

ethanneff avatar ethanneff commented on May 23, 2024 1

@JosephGarcia by moving the code from viewDidAppear() to viewDidLoad(), you will remove the Realtime Database from the app whenever a user open the Camera Picker. The database listener is removed within viewWillDisappear().

  override func viewWillDisappear(animated: Bool) {
    self.ref.removeObserverWithHandle(_refHandle)
  }

from codelab-friendlychat-web.

nicolasgarnier avatar nicolasgarnier commented on May 23, 2024

@iulukaya could you have a look?

from codelab-friendlychat-web.

ulukaya avatar ulukaya commented on May 23, 2024

It's related to your storage not enabled. If you just click the storage tab in your Firebase console, it'll set it up for you and upload will work next time you try.

from codelab-friendlychat-web.

bdonkey avatar bdonkey commented on May 23, 2024

@iulukaya
hmmm..not sure I understand this.
here is what i find in my storage tab:
image
and
image

I can upload a file from the storage tab in the console. However, in the code it bombs out to debugger both when I try to upload a file and when I cancel out of the upload attempt. Here is the code and dump when I try to upload an image:

FCViewController.Swift
image

variable dump
image

I don't want you or I to go down a rabbit hole here, so if there is anything else I can help you with to clarify, please let me know...thx...

scott

from codelab-friendlychat-web.

bdonkey avatar bdonkey commented on May 23, 2024

Update

Code bombs out in FCViewController function viewWillAppear

This Bombs

  override func viewWillAppear(animated: Bool) {
    self.messages.removeAll()
    // Listen for new messages in the Firebase database
    _refHandle = self.ref.child("messages").observeEventType(.ChildAdded, withBlock: { (snapshot) -> Void in
      self.messages.append(snapshot)
      self.clientTable.insertRowsAtIndexPaths([NSIndexPath(forRow: self.messages.count-1, inSection: 0)], withRowAnimation: .Automatic)
    })
  }

Commenting out self.messages.removeAll() the code does not bomb.
This runs but list prints out twice

  override func viewWillAppear(animated: Bool) {
//    self.messages.removeAll()
    // Listen for new messages in the Firebase database
    _refHandle = self.ref.child("messages").observeEventType(.ChildAdded, withBlock: { (snapshot) -> Void in
      self.messages.append(snapshot)
      self.clientTable.insertRowsAtIndexPaths([NSIndexPath(forRow: self.messages.count-1, inSection: 0)], withRowAnimation: .Automatic)
    })
  }

from codelab-friendlychat-web.

JosephGarcia avatar JosephGarcia commented on May 23, 2024

I have had the same problem. I moved the viewWillAppear code inside the viewDidLoad. Everything seems to be working fine. I am still a noobie but firebase is real time so I don't see why not just putting the observeEventType code into the viewDidLoad since its going to run still when you add a photo or text.

It is duplicating because viewDidAppear is running every time you dismiss the view controller associated with the Camera Picker. Just trying to help out. Hope this helps.

from codelab-friendlychat-web.

ecaplain avatar ecaplain commented on May 23, 2024

@ethanneff did you actually mean self.clientTable.reloadData() should be added to viewWillAppear() as instructed in the tutorial?

from codelab-friendlychat-web.

ecaplain avatar ecaplain commented on May 23, 2024

Slightly off topic, but I just noticed the image is saved wrapped in an optional. Looking for that and why "sent by: " is displayed in the chat view...

from codelab-friendlychat-web.

bdonkey avatar bdonkey commented on May 23, 2024

@JosephGarcia Thx for the comment. I was looking into what you were saying when @ethanneff helped clarify.

@ecaplain Yes is seems to me that @ethanneff meant viewWillAppear() and not viewDidLoad().

@ethanneff I tested this really quickly and you are right, the code stopped bombing into debugger. However it seems I am still getting double entries in my list when I add pictures. This could be a remnant of code on my part, so I will try look at further tomorrow...

here is my current code snippet where list prints twice:

override func viewWillAppear(animated: Bool) {
    self.messages.removeAll()
    self.clientTable.reloadData()
    // Listen for new messages in the Firebase database
    _refHandle = self.ref.child("messages").observeEventType(.ChildAdded, withBlock: { (snapshot) -> Void in
      self.messages.append(snapshot)
      self.clientTable.insertRowsAtIndexPaths([NSIndexPath(forRow: self.messages.count-1, inSection: 0)], withRowAnimation: .Automatic)
    })
  }

from codelab-friendlychat-web.

ecaplain avatar ecaplain commented on May 23, 2024

@bdonkey It's actually tableView() that gets called twice when an image is uploaded, not viewWillAppear, but I haven't figured out why yet...

from codelab-friendlychat-web.

hasrants avatar hasrants commented on May 23, 2024

i am having same issue here. The original code from Firebase tutorial crashes app when selecting a photo. Reloading table as specified here in this issue thread, just creates a dual "sent by" with username and then photo when clicked.

from codelab-friendlychat-web.

jmheist avatar jmheist commented on May 23, 2024

Same problem here. Loading the copleted app from firebase codelab, app crashes with "'Invalid update: invalid number of rows in section 0" As OP stated. Adding self.clientTable.reloadData() after self.messages.removeAll() in viewWillAppear() fixes the error, but loads the image twice in the table.

  1. The message is only added to the firebase database once.
  2. Deleting the entry from the firebase database does not auto remove it from the table list in app.

from codelab-friendlychat-web.

erickuhn19 avatar erickuhn19 commented on May 23, 2024

Hey everyone,

This thread on stackoverflow shows you how to solve this issue.

Need to add this code to viewWillDisappear

self.ref.child("messages").removeObserverWithHandle(_refHandle)

from codelab-friendlychat-web.

ulukaya avatar ulukaya commented on May 23, 2024

Updated the code to fix this problem

from codelab-friendlychat-web.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.