I am doing a Parse query from an external class. This query give me back the array for populate the tableview, so in the viewDidLoad method I call MyClass.load(array) and the async parse method findObjectInBackground return me the array filled but in the time that the findObject retrive me the objects the tableView is already created and I see an empty tableView, I did a fast google search for the problem and I found that I have to use the self.tableView.reloadData() method, I tried it but I am in an external class and the delegate for the tableView is in the tableViewController, there is any way to refresh the tableView from an external Class?
If you need some code example just ask it, thank you!
EDIT I'm using Swift 2.0
You need to set custom delegate between your external class and ViewControllers.
check for creating custom delegate
Also, you can use NSNotificationCenter for send and post notifications. please check link
Related
I have a custom TableViewController called LibraryTableViewController.
class LibraryTableViewController: UITableViewController {
contains this data for rendering.
var items: [item] = []
Then, I have another class for Firebase that inherits the LibraryTableViewController as a delegate. (I am not sure if this is the right description.)
class FirebaseDB : LibraryTableViewController {
Then, I have a global instance of FirebaseDB as
let database = FirebaseDB()
I have an observer listening to the changes in the database in the Firebase class, and I was updating
self.items
Then, trying to refresh the LibraryTableViewController using
self.tableView.reloadData()
I might be wrong in understanding my current problem. What I think is that the items array that I am updating isn't the same instance as the tableView that I see on the app. It is updating the FirebaseDB instance database's items which isn't being rendered on the app. How do I make sure that the right instance is being updated?
a lot of code missing
but you can check:
thread must be main, maybe you call from background
check is the items is changed
the numbers for you
check is the tableview not nil
check your delegate maybe its also nil
but better give us more code)
i am trying to access data from a remote json file. When something is typed into the searchbar a new NSURLSessionDataTask is made to access the json file. I have successfully been able to extract all the data i need from the json file, but have not been able to update the table view as soon as the data comes in. To show the data i must either scroll so one cell is not visible on the screen. This will make it so that only that one cell has the correct values in it, alternatively, i can also type in a other letter into the searchable which will generate a new json file, but the data from the previous request is only shown now.
I have tried updating the table view in the main thread but that doesn't seem to make any difference. I have also tried multiple other methods, but still no luck.
You can try like this
if let resData = swiftyJsonVar["loginNodes"].arrayObject {
self.arrRes = resData as! [[String:AnyObject]]
}
if self.arrRes.count > 0 {
self.tableView.reloadData()
}
Note :arrRes is the name of array.
complete details are :How get JSON Data in Swift and add it to URL
To get the best answer you'll want to post code, specifics, and maybe even a link to the full project, but based on what you are saying the data is loaded in the code properly and is not being refreshed in the table view.
To fix this you first need a reference to the table view that is not loading, for this example I'll call it tableView. Then you can force it to reload all the visible data by calling
tableView.reloadData()
After your JSON data has finished loading.
When your data is loaded successfully just call
self.table.reloadData()
What it will do is it will populate the cells again with the updated data.
I'm currently writing a social networking app for iOS using Swift and the Parse SDK. My app is basically a UITableView that displays a timeline of messages from users that sign up for my app. But there is one part that I'm struggling with that I hope the community will be able to help me solve.
My problem is that I want a user to able to tap on a message in my tableview and display the contents of the message and the user that sent it in a UILabel. I pretty much have tried everything I could think of to create this logic but I seem to make things worse. I'm pretty sure a PFquery needs to be used somewhere in this logic. I will attach my source code for my TimelineTableViewController and my custom tableview cell. Full code examples on how to achieve this logic in Swift will be very helpful since I'm already behind.
Thanks in advance
Derek Cacciotti
Twitter: #derekcacciotti
TimelineTableViewController
TableViewCell
In didSelectRowAtIndexPath, use the indexPath to help you figure out which message was tapped like so:
let message: PFObject = self.timelineData.objectAtIndex(indexPath.row) as PFObject
From there, get the values of your message by key (or create a Message class that is a proper PFObject subclass), then use those values to construct a string for your label.
I am trying to add records dynamically to an already populated UITable. In my UITableView class I have a custom List object
List<CustomObject> _data=new List<CustomObject>();
where I add records to from my webservice call like so:
_data.Add(Json(Object));// Json returns a list of CustomObject
//table is a UITableView
//this.table.InsertRows(_data);
I know this above line won't work because its expecting an NSIndexPath[] but I am not sure how to go about adding the new items an load only the new items added. I don't really follow objective C very well so examples I found don't help so much
Generally, you will add data to your List, and then call ReloadData() on your TableView. You usually only call InsertRows() if you want to insert data at a particular spot in the table based on some sort of user action.
You are trying to add a List of CusomObject as CusomObject to a List<CusomObject> ,that is not quite right.you should be adding a CusomObject to List<CusomObject>.
I have an NSFetchedResultsController to display a tableView.
And users are allowed to change the cells' order.
How can I record the order so that when users go to the view again,
the table displays by the order modified by users last time?
Thanks a lot!
Hey guys I've done this.
In order to re-order managedObjects fetched by a fetchedResultsController, the most official way I think is to give the entity another attribute of int, such as "order", and give this attribute to the fetch request of a fetchedController, and in table view delegate method "move row from .. to " something like that, deal with this attribute with your hands, and if you use a fetchedController delegate, set a flag in that delegate methods to indicate that you will modity the entity yourself, and notify the delegate to do nothing but return.
Sample codes are Apple Sample code Recipes, and hints on the documentary of fetchedController!