https://www.dropbox.com/sh/u9rkvwsrcdoa7q8/AABwKm_djSB2oENzuJNT1u35a?dl=0
include above, is the last iteration of this simple project I'm working on.
I am super close to achieving the basic fundamentals I wanted to practice with this project. Unfortunately, I am having trouble with the two cells with generic labels in the second table controller.
my first table controller displays these 4 restaurant types
let restaurantTypesArray = ["American", "Burgers", "Chinese", "Italian"]
if i choose "american", i want the array holding instances of (american) restaurants to be passed to the second controller. There, I want to simply display the name properties of the selected restaurants in my table.
This is my current view, if i select American in the first table controller I am just left with generic labels, indicated the values of the instances within the array.
I simply want these two labels to display the names "McDonalds" & "Burger King".
Any thoughts or suggestions towards a solution?
Related
I'm trying to create an app where multiple lists can be switched between using a button. Does anyone have any advice on the best way to do this, preferably using storyboard (my Swift skills leave a lot to be desired)? Right now I only have one list (a TableView) which is contained in a Container View, along with two other regular Views, one at the top and one at the bottom of the Container View, with the TableView in the middle. I want to have a button in the top regular View that switches between multiple TableViews. I want the number of TableViews to be dynamic, starting with one, but then the user can add additional tables as they need. Any advice on how to set this up would be greatly appreciated! Is it even possible to create a prototype TableView? Is that the way to go here? I've found a couple of Answers on Stack Overflow regarding multiple tables on a single screen, but these lists wouldn't be on a single screen, they would only be viewable one at a time: if you want to see the second list, you have to press the "Next List" button (in the View at the top of the Container View), and the first list disappears and is replaced with the second. Thanks everybody!
Don't change table views, change datasources. Use a single table view as you have it, and one array for each mode that the table is in (call those arrayA and arrayB). Another array-type variable -- call it theModel -- should be set to point to A or B.
The datasource methods will answer the count of theModel, and get values for the cells from theModel. When the user presses the button...
self.theModel = (self.theModel== self.arrayA)? self.arrayB : self.arrayA
self.tableView.reloadData()
// everywhere else, use theModel as the datasource
So I want users to be able to enter a search query, and should it return an empty or non-empty result the appropriate view is displayed (shown below):
As I'm fairly new to iOS I thought about the following possible ways of implementing this. I'm not sure if any one of these is deemed as good practice or maybe another better solution exists:
Create two separate view controllers with their own views that will display a message for empty search results or show non-empty results respectively
Create a single view that will house all of the components and show/hide certain components based on whether or not the results are empty/non-empty
Create a single view, but programmatically implement the methods for drawing the relevant components and just initialise the VC with the respective designated initializer (one for empty and the other for non-empty results)
The best practice is to manage the empty state of tableview meaning have a single tableview and display data when available, if no data is available display a friendly message in the tableview itself.
Below is the link that will help you implement the code:
http://www.ryanwright.me/cookbook/ios/objc/uitableview/empy-table-message
There are ots of examples available on net for managing the empty state of tableview.
maybe im not asking the right question, or maybe is not what i really need but the thing is in my app I have 2 Viewcontrollers, the first one with a picker view where you can find cities, you chose one and then you press a button that takes you to the second view controller, there you have and other picker view that shows you places according to what city you had chosen, but my problem is that I have a Label (in the second controller) that should show what you choose, so i think i must use different 'ifs' according to the place you have chosen, but it has to depend also on what did you chose on the first view controller and there is my problem, i don't know how to go forward with this.
Hope someone has an answer for that.
Im using Swift.
Sounds to me like you're using a master/detail design. On the first view controller you pick a city. That sends information about the selected city to the second view controller.
In the second view controller you'll look up the data to display for the selected city, and use that city-specific info to populate a picker (and anything else you need.)
You can either store your data for all cities in a global model and simply pass a city index to the second view controller, or you can have the first view controller "peel off" the data for the user's selected city and pass that data to the second view controller.
I am having a lot of trouble working with these Tables. I am porting an iPhone app over to the iPad. I have two UITableViews on the iPad, each with their own Controller. On the iPhone, these tables each have their own screen. When you get to the first table (a list of categories), you select a row, and then a push segue brings you to the second table (all of the items that pertain to that specific category). However, on the iPad, I cannot get the second table to update when a cell is selected from the first table. I cannot reloadData because I am having trouble telling the 2nd table what category was picked from the 1st table.
Some good news: Both tables show up on the root view controller (UIViewController). Table 1 shows all of it's categories, and table 2 shows all of the items from the first category from viewDidLoad (I programmed it to display the first set of items to ensure that it was at least working).
So my question is the line in the title, how do I change the content of the 2nd table based on which cell is selected from the first?
EDIT: I have more than just 2 tables on this one iPad view. I tried to post an image, but can't yet.. There are 4 table views, a custom Banner ad imageview, and some labels.
What you describe is a standard master-detail interface. I guess the detail view controller has a property defined in the .h file where you can set the new 'detail item'. If not, you need to add one (and you must currently have one in the init method or something).
Implement the setter method for that property, update the detail item and then reloadData.
This way you're just updating the existing view controller rather than trying to create a new one each time.
I'd recommend you create a new iPad (or universal) project in Xcode, select the master-detail project template and have a look at the code it contains.
I am parsing an XML document containing two branches from one XML document of the same sort of item (Topics and Schools), connected by a tabBarController.
Right now, Topics is populated, but I do not know the right way to go about populating Schools:
Should I create another viewController for School, or have some kind of conditional statement/selector sharing space with Topics in the existing viewController?
If its the latter, then how?
I want to do this right the first time, Please know that I know almost nothing. Thank you.
If both information will be presented in the same way within a cell of the table, you should use the same viewcontroller, what will change is the datasource. You can create a custom init method with an additional type parameter which can assume the values "Topics" or "Schools" and based on this value fill the array, from xml file, with appropriate elements.