Comments (15)
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.
@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.
@iulukaya could you have a look?
from codelab-friendlychat-web.
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.
@iulukaya
hmmm..not sure I understand this.
here is what i find in my storage tab:
and
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:
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.
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.
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.
@ethanneff did you actually mean self.clientTable.reloadData() should be added to viewWillAppear() as instructed in the tutorial?
from codelab-friendlychat-web.
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.
@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.
@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.
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.
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.
- The message is only added to the firebase database once.
- Deleting the entry from the firebase database does not auto remove it from the table list in app.
from codelab-friendlychat-web.
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.
Updated the code to fix this problem
from codelab-friendlychat-web.
Related Issues (20)
- Restore all changes that I or you made and all deletions HOT 3
- 83e7505c96ceba4d25adb3efc5ae8e35cba18b19/ restore
- aaeaef83b8976dedbf73d92bb48417d015eb61fe/restore
- Restore/all
- https://github.com/kikorobledo/
- Restore/all
- Restore/all
- Restore/all/to_original
- Restore/all
- Restore/all
- Restore/all/to_original
- Restore/everything_to/original
- 36570abc5bab35e6a27cf776a49924cf09f10a7f
- 36570abc5bab35e6a27cf776a49924cf09f10a7f
- 36570abc5bab35e6a27cf776a49924cf09f10a7f
- 36570abc5bab35e6a27cf776a49924cf09f10a7f
- 36570abc5bab35e6a27cf776a49924cf09f10a7f
- 0ab867bb94177c540145555f17d8b15a815d1dde
- # web-empresa-curso
- # web-empresa-curso
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from codelab-friendlychat-web.