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
Related
I am new to stack overflow and a student currently learning objective-C at university. I am building an APP for the science museum in London and I'm creating an events planner.
I have two table views set up in two different View Controllers.
The first View controller and table view is called "Events" and it holds all of the current days events. When you click on an event, it goes into a new View Controller, gives more information about the event and has a button to "Add To Events", which pops up an alert saying: "Are you sure you want to add this to your events?" with an add button and dismiss button accordingly.
The information in this table view is populated using three NSMutableArray's. (One for title, subtitle and image).
The second view controller has an empty table view inside it. I am trying to make it so whenever a user finds an event they like, they can click into it, see more info and if they want to add it to their own events page, they can. I have got the "Add" button of the alert responding using an NSLog message, so the code to implement the adding to events would go there.
My question is, if i click on the first event, and then choose to add it to my events, how do i send the information of that specific tableviewcell that i clicked to display in the second view controllers table view ?
I have looked all over the place for information regarding this and have taken an abundance of Lynda courses online about IOS and objective-C, but I haven't been able to figure it all out.
Can anybody help?
First of all you shouldn't use three NSMutableArray's to populate your cells. Create one NSMutableArray and populate it with NSDictionarys with a key for the title, the subtitle and the image. Or even better: create a custom model (subclass of NSObject) for your Events and populate the NSMutableArray with those.
Now just like your NSMutableArray is the data source for your first table view controller you need another NSMutableArray as the data source for the second table view controller. When a user now clicks on "Add To Events" all you have to do is add the Event (Model or Dictionary) to the NSMutableArray of the second table view controller and either call - (void)reloadData on your table view so that it reloads ALL data or use the "Inserting, Deleting, and Moving Rows and Sections" methods from the UITableView Class Reference. This would be the better approach because it does not reload data that does not need to be reloaded.
i have a view(page) with lots of textfields,date pickers, etc. This page is displayed using presentModalViewController. Now i want to save the data entered in the textfields to the tableView. Each textfields in the page corresponds to the column in the tableview.
I want to save the page's data on click of a button to the tableview as row wise.
Any Help !!
You could use a protocol and delegate object. Here is a simple example that will show you how to accomplish that:
http://www.theappcodeblog.com/2011/04/15/passing-data-between-views-tutorial-using-a-protocol-delegate-in-your-iphone-app/
Your View is presented from a ViewController, which is Controlling the View.
On clicking the save button on the View, the ViewController can pull the data from the fields in the View, and save them into a Model object which you can then add into your UITableViewDataSource array (or whatever you have to load data into your table).
You can then tell your UITableView to update row at index path, and it will pull the new data from the datasource and update your table.
Voila....
... a cleverer (is that a word) approach would be to bind your Model properties to your View elements (from your controller), so as they are updated, the model changes. The table could be using KVO to listen for Model changes and update their view components at the same time.
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?
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 table view, and I want to add a row, and save it to coredata.
So is this a good practice:
when user clicks the "plus button" on navigation bar, on the screen will appear new view controller, where user can write required data for new row. When the user clicks "done" button, controller by delegation will trigger an addRow method (from RootViewController) which save data to database.
Yes, it does seem fine. The delegation is also responsible for the table view reloading once you added new entry, if your data source is stored in NSArray or other collection.
If you use NSFetchedResultsController, it will reload automatically once detects the changes made to Core Data entity.