60838

How make your tableView show new or update element at the top of your tableView PT.2

Question:

I can't seem to get new messages sent from new user or new message sent from users already in tableview to go to the like with most messaging apps. I've ask this question before and tried to follow the directions in a link that someone kind enough to send me (<a href="https://stackoverflow.com/questions/37144030/how-do-you-properly-order-data-from-firebase-chronologically" rel="nofollow">How do you properly order data from Firebase chronologically</a>) but I still can't get the desired effect no matter matter I try

func getChatsFeed(){ //following the links instruction "timeStamp" is suppose help return fireBase children in reverse order. "atValue: time" is a value for the time when my viewDidload. let queryChats = Database.database().reference().queryOrdered(byChild: "timeStamp").queryEnding(atValue: time, childKey: "timeStamp") queryChats.observe(.childAdded) { (snapshot) in if let snapvalue = snapshot.value as? Dictionary<String,Any>, let sender = snapvalue["sender"] as? String, let receiver = snapvalue["receiver"] as? String, let message = snapvalue["messageBody"] as? String, let key = snapvalue["key"] as? String, let timeStamp = snapvalue["timeStamp"] as? String{ let newMessage = FeedMessage(sender: sender, receiver: receiver, messageBody: message, key: key, timeStamp: timeStamp) feedUpdate.append(newMessage) self.chatsTableView.reloadData() } } }

The link I included received a respectable amount of praise for being solution a to a lot of StackOverflow users problem so maybe I messed up somewhere, being not fully in the know of all the different Firebase methods, this could be the case. Any pointers anyone?

Answer1:

With the other approaches, you've used where data is loaded into feedUpdate, simply do this:

chatsTableView.reloadData() let indexPath:IndexPath = IndexPath(row:0, section:0) chatsTableView.scrollToRow(at: indexPath, at: UITableViewScrollPosition .top, animated: true)

Recommend

  • Why calculations of eigenvectors of a 2 by 2 matrix with numpy crashes my Python session?
  • TypeScript Mapped Types: Get element type of array
  • Play WS API: throttling request rates
  • Passing matrices from function to function in MATLAB
  • How to process a big array applying a async function for each element in nodejs?
  • Vertical align DIVs
  • LINQ to NHibernate WHERE EXISTS IN
  • Converting a data frame into named object in R
  • Can you look sample a texture in a vertex shader?
  • How to get text which is not part of any element using jsoup?
  • D3 v4 force layout disable animation on drag
  • What does the lower left pane in OllyDbg displays?
  • Restrict an object to stay within another object
  • How can I apply differnt styles when transforming data using json2html based on data value?
  • PHP Handling Namespace with SimpleXML
  • Floating-point number in Excel
  • Finding parents in a tree hierarchy for a given child LINQ (lambda expression)
  • TypeError: 'builtin_function_or_method' object has no attribute '__getitem__'
  • Cannot update firebase version [duplicate]
  • How to sort things out in ListView?
  • Firebase firestore cloud functions showing trigger type 'unknown'
  • Safari PHP form submission -file upload hangs
  • Angular2 emit event up to the DOM tree
  • How do I obtain a list of files that changed from svn over a date range?
  • Firebase, only get new children
  • Is mp4 stream able with ffserver?
  • How to get value from merged-cells in Excel document using OpenXML and C#
  • Python/Javascript: WYSIWYG html editor - Handle large documents fast and/or design theory
  • IE10 strips out hashtag from the URL
  • New Firebase failed: First argument must be a valid firebase URL and the path can't contain “.”
  • Can I have a variable number of URI parameters or key-value pairs in Laravel 4?
  • Invalid Date on validation Date of js
  • as3-flash: any way to access all the instances placed in different frames from document class?
  • How to disable all widgets inside Panel or inside Composite?
  • Does it make sense to call System.gc() and Thread.sleep() when working on Bitmaps?
  • Caching attributes in superclass
  • Django query for large number of relationships
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • How can I use `wmic` in a Windows PE script?
  • How to push additional view controllers onto NavigationController but keep the TabBar?