New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ios error when trying to add photo #25

Closed
bdonkey opened this Issue May 20, 2016 · 15 comments

Comments

Projects
None yet
9 participants
@bdonkey
Copy link

bdonkey commented May 20, 2016

  • running complete ios project.
  • Adding messages no problem
  • When trying to add a photo, app bombs with following error

2016-05-20 14:37:10.156 FriendlyChatSwift[32573:72997859] *** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.60.7/UITableView.m:1716 2016-05-20 14:37:10.162 FriendlyChatSwift[32573:72997859] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (1) must be equal to the number of rows contained in that section before the update (7), plus or minus the number of rows inserted or deleted from that section (1 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).' *** First throw call stack: ( 0 CoreFoundation 0x0000000108852d85 __exceptionPreprocess + 165 1 libobjc.A.dylib 0x000000010a9bddeb objc_exception_throw + 48 2 CoreFoundation 0x0000000108852bea +[NSException raise:format:arguments:] + 106 3 Foundation 0x0000000108ca3d5a -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 198 4 UIKit 0x00000001095394ca -[UITableView _endCellAnimationsWithContext:] + 15146 5 UIKit 0x000000010954fcf0 -[UITableView _updateRowsAtIndexPaths:updateAction:withRowAnimation:] + 303 6 FriendlyChatSwift 0x0000000105a13f16 _TFFC17FriendlyChatSwift16FCViewController14viewWillAppearFSbT_U_FCSo15FIRDataSnapshotT_ + 774 7 FriendlyChatSwift 0x0000000105adf419 __63-[FIRDatabaseQuery observeEventType:withBlock:withCancelBlock:]_block_invoke + 37 8 FriendlyChatSwift 0x0000000105b064bc __43-[FChildEventRegistration fireEvent:queue:]_block_invoke64 + 88 9 libdispatch.dylib 0x000000010b467d9d _dispatch_call_block_and_release + 12 10 libdispatch.dylib 0x000000010b4883eb _dispatch_client_callout + 8 11 libdispatch.dylib 0x000000010b4701ef _dispatch_main_queue_callback_4CF + 1738 12 CoreFoundation 0x00000001087ac0f9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9 13 CoreFoundation 0x000000010876db99 __CFRunLoopRun + 2073 14 CoreFoundation 0x000000010876d0f8 CFRunLoopRunSpecific + 488 15 GraphicsServices 0x000000010c8bcad2 GSEventRunModal + 161 16 UIKit 0x0000000109409f09 UIApplicationMain + 171 17 FriendlyChatSwift 0x0000000105a1974d main + 125 18 libdyld.dylib 0x000000010b4bc92d start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException

@nicolasgarnier

This comment has been minimized.

Copy link
Member

nicolasgarnier commented May 20, 2016

@iulukaya could you have a look?

@ulukaya

This comment has been minimized.

Copy link
Member

ulukaya commented May 20, 2016

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.

@bdonkey

This comment has been minimized.

Copy link

bdonkey commented May 20, 2016

@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

@bdonkey

This comment has been minimized.

Copy link

bdonkey commented May 21, 2016

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)
    })
  }
@JosephGarcia

This comment has been minimized.

Copy link

JosephGarcia commented May 22, 2016

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.

@ethanneff

This comment has been minimized.

Copy link

ethanneff commented May 23, 2016

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)
    })
  }
@ethanneff

This comment has been minimized.

Copy link

ethanneff commented May 23, 2016

@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)
  }
@ecaplain

This comment has been minimized.

Copy link

ecaplain commented May 24, 2016

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

@ecaplain

This comment has been minimized.

Copy link

ecaplain commented May 24, 2016

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...

@bdonkey

This comment has been minimized.

Copy link

bdonkey commented May 24, 2016

@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)
    })
  }
@ecaplain

This comment has been minimized.

Copy link

ecaplain commented May 24, 2016

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

@hasrants

This comment has been minimized.

Copy link

hasrants commented May 25, 2016

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.

@jmheist

This comment has been minimized.

Copy link

jmheist commented May 25, 2016

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.
@erickuhn19

This comment has been minimized.

Copy link

erickuhn19 commented May 29, 2016

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)
@ulukaya

This comment has been minimized.

Copy link
Member

ulukaya commented Jun 7, 2016

Updated the code to fix this problem

@ulukaya ulukaya closed this Jun 7, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment