Add Data From One Table To Another Table - iphone

I have a tableview with genre: rock, rap, dance, country, pop, etc.
Lets say I have another tableView where I can make a custom list with a bunch of these genres.
Say in the mainView, I can add lists, like Dinner, Gym, Studying etc. Then within each of these lists (when you click its cell it will push to a subtableview for that list). I want to choose items from the separate genres to add to this subview. Examplple, Dinner list might include country and classical music, and gym list might have rock and rap etc.
I have everything set up so far except the code that lets me add genres to the custom sub groups. So I can make groups such as Dinner but I need to still make code that lets me fill this group with genres from the other tableView.
I think I need to have a modal view pop up when I click the add button. THis model view will have the genre table and when I click a cell, the modal view will dismiss and it will add whatever I clicked as a cell in the group.

Use the same genre array that backs the genre tables as the data source for the modal table.
In the modal table didSelectRowWIthIndexPath, get the genre string from that array.
Now you have lots of choices for how to get the genre item back to your detail table view controller.
You could post a notification, you could use a KeyValue Observer, you could pass a reference to the detail VC to the modal and then the modal can set an exposed attribute on the detail VC, etc.
Then the detail vc would add that genre value to whatever array is back it's data, and then you call reloadData on the detail VC table.
Your modal VC would have to do something like [navigationController popViewController:animated] to dismiss itself.

Related

How to handle views inside views when using the back button in SwiftUI?

I have an App which lists all my ToDos by category.
To do this my, inital thought was to write two For Each Loops. The first one to iterate over the groups and the second to itereate over the todo items per category.
But XCode said, that this was too complex to handle in one single view.
So I split up the views.
HomeView.
ForEach category display RowView (parameter: category).
ForEach todo display DetailView (parameter: category, todo).
-> The DetailView holds the NavigationLinks for the respective todo.
Now when I click on a todo and try to navigate back with the built in back button, does this cause problems with the user interaction?
Because after going back, I can't click on any todos anymore.

For Each Detail View Data to Main View

I don’t have any code for this, so I’ll make up a hypothetical situation:
I want to make a grocery list app. I have a tab bar that sends me to a view where I can create categories in a list (fruits, vegetables, dairy etc.) Each category sends the user to a detail view where they can list off certain brands and the amount they need.
(This is where it gets a bit tricky)
In the main view, the categories that the user made are now tabs that are on the bottom and the list they made in detail view appears on the screen. Any changes they make in the list shown (in the main view) will update back into the specific detail view.
Is that possible? And what technique would be used for something like this?

Segueing with a reusable table view

I am working on a directory listing application. Specifically, the app I am working on is called iEngineering. It would probably be best to drive home the purpose of my question if you download or look at the application on the AppStore. It is available for free. I would like to use one view controller with a table view to navigate to a similar view controller with table view. For example, selecting “Chemical Engineering” transitions/segues to a new screen with a new listing that displays sub categories within chemical engineering. Currently, my project requires two view controllers with table views for this process but I would like to condense it down into one single view controller with table view. Thank you all for your time and any guidance you may be able to offer me :)
You only need the firstVC with a datasource array for the table , then when you select a category , instantiate a vc from that vc and send the array to it something like this
Inside ( didSelectRowAt ) of that SameVC
let vc = self.storyboard.,,,,,,, as! SameVC
vc.arr = arr.subCategory // set the sub to the new table
self.navigationController?.push///// // push not segue
Sure you will check if there is a content inside arr.subCategory before doing this as there will be leaf categories
Note: arr and subCategory are of same data type as it's a nested process

Moving table view cells from one view controller to another

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'm trying to add a tableviewcell from one table to a different table Xcode

I am developing an iphone app for a class project and am displaying a bunch of different products. I am trying to create a favorites page where users can add one of the products to their favorites page. The app is set up with a bunch of different tableviews to display the different products along with their piture, name, price, and description. I want the user to either click on my addtofavorites button I will add to each of the table view cells or I was wandering if I can just use the didSelectRowAtIndexPath method in the tableviews to add all that information to the favorites table view. Thank you
First, look into following the MVC pattern,
a good introduction: https://developer.apple.com/library/mac/#documentation/General/Conceptual/DevPedia-CocoaCore/MVC.html
That being said, I'd have a products UITableView, in a view controller. The user can then select the view controller and in the didSelectRow: method, find out which product was selected to sou can pass the data through a delegate patterns (other ways include target-action, NSNotification, etc.) for example like this: (good example of passing data: Passing Data between View Controllers) to a separate view controller which would hold your favorites table view. Make sure the model is separate from both the products view controller and favorites view controller so you can save all the name, price, etc whatever properties you want to save.
perhaps all of this would be contained in a UITabBarController so it's easier for the user to go back and forth between products and favorites.