I have a TableViewNavigationController. On my first page, i have displayed a table-view, and on the navigation bar there is a add button, where the user could add a record.
once the user clicks on the add button, a UIView will be displayed and the user could enter details and submit, and then when the user clicks on the back button on the TableViewNavigationController, the first page which contains the table-view is displayed with the added record.
But, for me multiple records are displayed, and when i restart the stimulator it shows the correct set of records. Why is this and how can i prevent this?
EDIT : Can someone tell me which method fire's when we click the back button of the TableViewNavigationController ?
Are you updating the datasource of your tableview with the right array-data?
If not,
[yourTableView reloadData];
Should fix that.
You likely need to use the reloadData method for your tableView when returning to the table. And possibly refresh your data. Is it coming from an array or using fetched results controller? Either way, it sounds like you're seeing odd results because the data has changed.
You should show us some code, so we can help you more.
The method that get's called when you change a view is the viewWillAppear
Since you mentioned that you are reloading your Table Data Source, are you sure you are adding the new entry to your existing Data Source (your Array) ?
Is your Array an mutable Array, so you can add the new record to it?
Related
I am trying to add a label to the window whenever the tableview item count is zero. I figured that the best way to do this would be to check tableView.numberOfRows after tableview reloads . However, I can't seem to find a way to detect it when the tableview reloads. Is there a way to do this?
Table views don't spontaneously reload. You tell them when to reload. You should probably have a central data model object, and have it notify your view controller when the items count reaches zero. (You could set up your data model object to have a delegate, for example, and give the delegate a itemCountChanged(to:) method.)
So i have a search page. The word the user searches is passed to the next view controller. Now instead to using prepare for segue and passing the value, I store it as a global variable and just to a performSegue.
The problem is when I go back using the back button of the navigation controller, the new data doesn't reload when I click on search. It shows the old data.
Link of the images is given below. Now 1st one is a search for Rahul. It shows the correct result now the next is when I go back and search for Rohan it shows the result for Rahul itself.
https://i.stack.imgur.com/irUwo.png
https://i.stack.imgur.com/fthOm.png
https://i.stack.imgur.com/F7wKJ.png
Once perform to the result view controller, ask your main thread to call tableView.reloadData() after you received the new global value you pass. If this can't help you, please provide your code so that we could help you by clearly understand your situation.
I'm using core data for a tab bar + navigation controller prototype app, with one entity: Event.
So I have two tabs, the past and the present. I'm using nsfetchedresultscontroller and nspredicate to filter the data into their respective table views.
now here is where i'm having a problem, when i create a new date, it shows up in the present table view like i expect, but as time goes by the event stays there past the date, and never moves to the past table view. The only way i can achieve this is just launching the app from scratch, killing the background view.
I've tried to install reloadData call to table view in view will appear. That doesn't work.
I tried to use [tableview reloadData] when the app launches from background too. but that doesn't work too.
I can't think of anything else, hoping you guys could help.
[Edit]
I just figured out how to do it! I tried to download the sample code i thought i uploaded to github, but looks like there is no file there. I cant figure out how to upload the project up there.
anyway, the thing to do to achieve this is in the view did appear, just place in the entire fetch request that's in the fetched results controller (without the fetched results controller variables) with the predicate. now if the moment you switch views, the entire data is updated and filtered!
Hope this helps anyone else looking for a solution to this problem.
Uhm, if you have already tried reload data, these others could be possible problems:
be sure the cache is consistent with the predicate. If in table
controller you use a cache, and the table is populated with something
like entityDate = myCalculatedDate then the predicate could be different,
and you need to delete cache first. I think you could try to set
cache:nil to see if this is the problem.
for updating table, especially with new inserted rows, or moved rows
to different index you need to implement the fetched controller
delegate
[EDIT] also if I remember well, I am not sure if standard
mechanism of viewWillAppear/dissappear works as expected with Tab Bar,
probably there's some delegate to implements, but it's just a
guessing !
this what I can guess without seeing the code.
I have a small query.I have made an application in which i am fetching information from the webservice and i am displaying it on the table view.The table view which i a using is customized one in which i have used the text and the image property.
These things are working fine but now i have added a button ,once i click on it then a new view appears which has 2 options for 2 countries whose webservices are provided to me ,once i click on one button and see the table view then the list of the previous table view only appears and if i scroll through the whole list then the values changes which is according to the webservice.
So kindly suggest me as in what should be the approach of directly showing the updated tablecells.
[tableView reloadData];
call it explicitly from the secon view, or you can put it in viewWillAppear
I have a tab-Bar Controller + UINavigation Controller app.
In tabs 1,2,3 I have table views that offer the user some items to choose from. Once the user selects the items they get added to a Cart.
Tab 4 is a table that shows the items in Cart.
I noticed that when the user selects items in tabs 1 or 2 or 3 they show ip in the cart tab the forst time its clicked on.
If the user then goes back to tabs 1,2,3 and selects more items, the table in the "Cart" tab does not get updated.
Im not sure why this is the case. I have programmed in the "Cell for Row # IndexPath" method to get data from the Datasource each time this method is called.
Im puzzled. Wondering if there is something obvious that Im missing here?
Thanks for your help
The table only updates its data in two situations.
You're using an 'NSFetchedResultsController' to bridge the gap from your data to the view. This controller automatically updates the view whenever the underlying data changes (and, similarly, automatically updates the data when it receives an add/edit/delete request from the view).
You handle it all manually in your own code, most importantly calling the UITableView's reloadData method after the data in the datasource has changed.
you have to reload the data in the table view friend .
[yourtable reloaddata];
use this where you want to show your data