How to relate data to a specific row in a UITableView - ios

What I basically want is to show the user's name in the first tableView but have a disclosure indicator (segue) to go to a second tableView which will show the history of the selected user. I know how to load data into a table and how to segue from one row to the detail table but I just don't know how to show different data for each user. I know this may be out of my scope of knowledge at the moment but I would like to give it a try.
1- What would be the best way to store the data for each user (history), an array per user?
2- How can I relate data to a specific user so it loads when the user's name is touched?
3- How can I capture the row being selected?
Any suggestions will be appreciated.

Honestly, you shouldn't worry about it being outside of your scope of knowledge, as that's how people learn. You will need to do some amount of work, however, and that part can be a little difficult.
Luckily, what you're trying to do is a very well documented function and Xcode even provides a template for master -> detail views.
Check out this wonderful tutorial by Ray Wenderlich on creating a simple master-detail application: http://www.raywenderlich.com/1797/ios-tutorial-how-to-create-a-simple-iphone-app-part-1
His other tutorials will also be immensely helpful to beginning iOS development: http://www.raywenderlich.com/tutorials

Related

How to create a dynamic drop down within a table view?

I need to create a tableview with at least two sections, transportation and hotel. Tapping on either one creates a drop down view showing info on 1 to n examples of the topic selected. You don't know in advance what data is going to be there so it has to be dynamic to present any number of results with some having lengthy descriptions below each example and some not. I've been racking my brain and I can't figure out how to do this. The dynamic nature of this makes it extra difficult. Here is a mock up of what it should look like: click here
Check out this Git-Repo. I am using it inside my app and its working quite well. You can also watch the tutorial for it: https://www.youtube.com/watch?v=22zu-OTS-3M&t=1s
Hope that helps!

How to create a table in swift with segue?

I'm brand new to Swift but I want to create an app that has a table and each entry in that table will lead to a new screen (but this new screen is the same for all the table entries) but depending on which table cell you click on, that screen has different information posted on it.
What are the steps I need to do to complete this? I have my story board I'm just not sure how to put this all together with code
Thanks in advance!
Well your question is very broad and not very specific. Therefore it is not easy to give a helpful answer. What I would do:
Create a UITableViewController that holds your "table".
Define a UITableViewControllerDelegate for the UITableView that will be informed about UserInteractions (especially when the user
didSelect a certain row of the table).
Based on the specific row (that was selected) you can create a second UIViewController class the shows your intended information.
I can not show some code samples because your question is to broad and things depend on a lot of things (especially on the kind of data you want to show) and how you implement your UIElements on the ViewControllers in InterfaceBuilder.
And if you are not yet familiar with the concept of a UITableViewController and its Delegate, than you should find some tutorials first about that basic technique in developing iOS apps.
You want to use the master/detail pattern. I suggest doing a search on that.

How can I create a UIView that displays certain information based on the button that was pressed to show the view?

I am very new to swift and currently making an app for a school project. The app is supposed to show a collection of recipes. I have begun by having a scrolling grid of buttons (stackviews and scrollviews). Each recipe is supposed to connect to a specific recipe, and when clicked segue to a view that has the information for the recipe (image, ingredients, instructions, etc.). I would like to do this by creating a a basic recipe view file that has a space for an image, title, and text. Then, depending on what button was pressed, fill in the view with the correct information and display the view.
I have figured out an alternative method that I could use, but it is very bulky and tedious. I could set up views for the ~25 different recipes separately, and link them individually to each button.
I would much rather prefer the first option, but I am not quite sure if it is even possible, or if I am just really bad at using the right search terms in google. I know many other apps have similar systems set up, for example a social media profile is the same template for everyone, just has different data displayed inside of it.
Can anyone help me out? Thanks in advance.
You can use UITableView for this task and have a model array that you fill with the required data ,and for action use didSelectRowAt to find which cell is clicked send the data to the next VC

Taking user input and displaying it in multiple view controllers in Swift?

This is my first post about Swift and I hope someone can help me. I'm a junior Ruby/Rails developer and have recently started building an app for a personal project to get to grips with developing in Swift and XCode, as it is something I am interested in moving into.
I have just started building my app, but have hit a problem almost straight away that I have been unable to find a clear answer to or any guidelines that I can bend to serve my purpose. I'm sure it must be a fairly simple issue to solve, so I'll try and write my problem as clearly as possible:
If I want to take some user input from a text field, such as a name or a location, and then display that input in another view controller, how would I go about doing it?
So far in my app, a user is presented with a button, which when pressed, shows a view controller with two text fields. I want to take the input strings from the two text fields and display that data in a label on the next view controller, so the user can add more information to the object before publishing it to be displayed in a table view cell elsewhere in the app. I have used IBOutlets on the text fields.
I have been reading about Core Data in Swift and have worked through a couple of tutorials about adding data to a table view, including the Start Developing iOS Apps (Swift) from Apple and I think I'm on the right track to finding out how to achieving the functionality I want. But I'm not entirely sure, and wanted to ask if I am on the right path or if I'm going about it the wrong way?
If anyone could link me to any tutorials or guides or point me in the right direction so that I can figure out what seems like a basic step of storing data that can be retrieved and displayed in other view controllers, I would appreciate it very much.
Thank you in advance.
You may do it by many ways -
If you want to take input string to the immediate next UIViewController, then when you navigate to another UIViewController , initialise two string object of that view from current UIViewController and then navigate. In that UIViewController you can have your string.
If you want to use those strings in some other UIViewController then you can take two string variable in AppDelegate(That is a global class) and set them from current UIViewController and you can use them whenever you want.
If you want to permanent save that data then you can better use NSUserDefaults ( NSUserDefaults - storing and retrieving data )if it is only 2 or 3 or some little amount of field data. If data is more you can use database.
Try these links :
http://jamesleist.com/ios-swift-passing-data-between-viewcontrollers/
How do you share data between view controllers and other objects in Swift?
http://blog.apoorvmote.com/how-to-pass-data-via-multiple-segue/

Multiple TableViewControllers & Segues

I have a TableView that is populated with data. When a user taps a row, a new TableView opens with more data to choose from. This data changes based on the row the user taps. Much like an application where the user chooses from a list of car makes, and then models. Is it possible to handle a situation like that with a TableViewController for the car makes, and 1 TableViewController for the models? Or would there be 1 TableViewController for the makes, and then a separate TableViewController for each make's set of models? I don't know the best way to approach this :-( I'm making an app of my own which is very similar in structure and I can't seem to find any documentation on how to accomplish this. Thanks in advance.
No, your models controller would serve for all makes. It would be passed an ID of the make requested and then fetch the necessary data accordingly.
Something like this might be of some help:
http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/TableView_iPhone/TableViewAndDataModel/TableViewAndDataModel.html
But I think the foundation of your problem is not necessarily to be found in a working example of your exact needs, but more in general tutorials for ios development.
Sorry if I have assumed you're just beginning ios development. I might be able to improve this answer if a more specific need is clarified (like how do I pass the ID to the model controller) etc
In general - this approach would utilize a separate UITableViewController for each data level and use a UINavigationController to handle the transitions between the different view controllers.
This process used to involve a lot of boilerplate code, but it is now aided by StoryBoards. You can setup each level in a storyboard and handle the transitions and setup data for the next view in performSegueWithIdentifier:.
You can see a tutorial here on using StoryBoards: http://kurrytran.blogspot.com/2011/10/ios-5-storyboard-uitableview-tutorial.html
You can see another Sample From Apple that demonstrates the data drill down with a Storyboard: http://developer.apple.com/library/ios/#samplecode/SimpleDrillDown/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007416-Intro-DontLinkElementID_2

Resources