I have 4 different views, all that have their own table view with data. I want to make a 5th view/interface that has a table view that consolidates the other 4 tableview data into one.
For each of the 4 initial table views, I am storing the data using Core Data, and each table has its own entity with multiple attributes. Im looking for the theory about how to consolidate all these into one tableview. Any help would be great, or if you can point me in the right direction.
So essentially i have 4 table views all with their own data, and i want to make a 5th table view that shows all the data.
Thanks so much!
I guess what I would do is to store all the data of all the table views in a single mutable dictionary that contains sub dictionaries that contains each table view data like so:
MainDictionary >
---tableview1Dictionary
---tableview2Dictionary
---tableview3Dictionary
---tableview4Dictionary
I would save this dictionary on the NSUserDefaults so it can be accessed from each view controller in your app.
On the fifth view controller you can simply load this MainDictionary data in to your "combined" table view. This way whatever changes you make on any table view will directly effect your combined table view and all your data will be synced.
You can reload each table view on your controller viewDidAppear.
NSUserDefaults Tutorial: http://www.icodeblog.com/2008/10/03/iphone-programming-tutorial-savingretrieving-data-using-nsuserdefaults/
Hope that helps.
Related
I use firebase database and table view. I put there an object. The code:
thingManager.addNewThing(thingName.text!)
let thingRef = self.thingsRef.childByAppendingPath(thingName.text!)
thingRef.setValue(thingManager.toAnyObject(thingName.text!)
All of the elements from database are displayed in table view. Table view is loaded everytime the application starts.
I load the table view by having an array from which table view takes info. Everytime the app is loaded, the array is filled with elements from database.
The problem is that the elements duplicates in table view when I add new object to the database. The data doesn't duplicate in the database itself, but it duplicates somewhere in that array. Tried multiple things and when I delete the last two lines
let thingRef = self.thingsRef.childByAppendingPath(thingName.text!)
thingRef.setValue(thingManager.toAnyObject(thingName.text!)
everything works fine, but the data is now not saved in the database. My question is: can these two lines cause the duplication? Thanks in advance
I had this same issue. I was loading the Firebase Data into a GLOBAL Array of structs. I was able to fix my issue by switching the Array to a LOCAL array in my tableView class. Let me know if this helps:)
your code is not very clear, but i think you need
dispatch_async(dispatch_get_main_queue(), {
self.YourTableView.reloadData()
})
As the title describes, I've got a tableview inside each of my collection view cells. For me, it makes sense that the superview's controller should control the view, but since in this case each tableview contains different data, I have made each superview (collection view cell) the controller for its tableview. I hope that makes sense. I know making a view to also be a controller violates the MVC paradigm, but I'm not sure what the proper way is achieve MVC compliance in this case. I also need to send messages to the table view based on what happens in the CollectionViewController. Do I need to subclass UITableViewController and make a reference to it in my collectionviewcell.h file?
Sorry if that was confusing. Thanks for the help.
I think your instinct is correct that having a view object serve as a data source is a violation of MVC. I would suggest having the owning view controller either serve as the data source for all the table views, or set up a separate model object for each table view that serves up the cells for that table view.
If you use a single data source you'll have to have a switch statement that figures out which table view is asking and fills the cells with the appropriate data.
My gut would be to create a thin table view data source class who's only job is to serve up the cells for the table view inside a collection cell (and respond to the other collection view data source protocol methods). Use a custom subclass of UICollectionViewCell that has a strong property that points to the data source object. You could make your custom cell class create an empty data source object at init time and hook up it's outlet to the table view.
Then in your cellForItemAtIndexPath method, pass the appropriate data to the cell's data source object. If you reuse a cell, it would already have a data source object, so you'd just replace the data with new data and trigger the reloadData method.
Your controller object would mediate between the model and the view, like it should. It would set up the model data for each cell, and then the data source object for each cell would act as the model for that cells table view.
If you later come up with several different types of collection cells that display different data, using separate data source objects for each cell would keep the code simple. You'd just subclass your data source object based on the cell type.
This is my situation: I have a table viewcontroller and I use core data so each cell created by user goes to a detail view with different data.
For example, taking the data of a label in a detail of a cell 4, and the label data from the detail in cell 5, and so on
My idea is to make something with this data from each information of each cell and show it in my "home" window.
MY QUESTION: How to take the information of the label of the detail of each cell created by user, and put it another place?
Don't use labels and other UI elements to store data. Instead, set the UI elements to reflect data that is stored in an underlying model of some kind.
If you model the data, you can access the underlying data model from any view and you don't need to read values from UI elements from other views.
This is a standard approach of the MVC design pattern used in Cocoa.
I am trying to create an application with multiple table views that uses and implements Core Data. I would like the user to be able to select cells in one table and move them to another (like in Apple's mail application) using either a check accessory or a selectedCell method with an action sheet. I'm stuck because I don't know if you are actually moving the cell to another table or if you are adding a copy to the new table and deleting the original. Basically, I'm asking for a basic example of cell movement to give me a push in the right direction.
You won't be moving cells. The model for a table view is an array. Move things between the arrays and tell the tables that their model has changed.
id somePartOfMyModel = [self.arrayA objectAtIndex:someIndexPath.row];
[self.arrayA removeObject:somePartOfMyModel];
[self.arrayB addObject:somePartOfMyModel];
// the simplest, non-animated way to update the tables.
// I'd advise getting this working first, then later trying fancier UI to indicate changes
[self.tableViewA reloadData];
[self.tableViewB reloadData];
You would not be technically moving the cell to the other table. The way I would go about doing this would be to pass the NSManagedObjectContextID of the item between the tables, depending on how large your entities are and if the tables are in the same view controller.
i have a slightly confusing problem here. I am using storyboard i have a tab view controller tab 1 has a table view controller (table 1) which on selection of a row goes to table 2 and some data is added to the table 2 here n it is shown on table 2 cell when i navigate back to table 1 and go forward again to table 2 that data is lost ..how can i save the data then so that it can still show the saved contents. thanks
It's because the navigation controller releases the second view controller when you go back from table 2 to table 1. If there were no other references to the 2nd table view, it gets deallocated. I suppose you're also creating the table view every time you select a row in table 1. Try to keep a reference on the second table view, and not re-create it every time, only on initialization.
Sounds like you need fixed data storage. You can use Apple's Core data for this. See Apples documentation on Core Data or see "Pro Core Data for iOS" by Michael Privat. Then each view controller can store and retrieve data from the permanent store. Be aware that learning core data takes some effort, but it is worth because you will find yourself using it time and again. I also ran across this project arraydatatable which provides a structured data solution without using core data. Also, since you mentioned that your are new to iOS you should read Apple's documentation on their recommended Model View Controller (MVC) structure. In that structure the Model is your data, the View is what you see on the screen, and the Controller controls the view as well as fetching and storing data to the model.