I have multiple ViewControllers all linked to an initial ViewController. Each of the extra ViewControllers acts as a 'tennis court', with player1 and player2's names entered into UITextFields, and then stored in an array.
Is it possible, using a UISearchBar on the initial ViewController, to search the name of a player stored in one of the various variables, and then for that result to link to the ViewController within which it appears?
Recall MVC.
You never store your data or model in any viewControllers. You store them in a model that may be an array, dictionary, or plist or even a database.
So you need to search from the model using your UISearchBar.
*If you show your code, we can correct them.
Related
I have an array of users
var selectedUsers = [User]()
users are added to this array as they are selected in a UITableView (see screenshot: https://www.dropbox.com/s/uk03mhgi3x4jesy/File%2006-10-2015%2C%2018%2003%2044.png?dl=0)
What I'm having difficulty with is when I press back and then reload the view controller, all the checkmarks disappear.
Is there anyway I can keep track of the selected cells?
Thanks in advance
You could use a delegate to pass a array between the two viewcontrollers. For example, each time you select a row, you can store the userId's associated with the row, in the array. So if you were to press back and then open the view with the UITableView, before you load the UITableView, you can first check if there is an array being passed to the viewcontroller containing the UITableView / if there is an array, check if the count is greater than 0. If the array is not empty, then use a for loop to cycle through the array of users being displayed with the array being passed containing all of the previously selected id's, then add the check marks that match up to the Id's in the array.
Here is a tutorial that possesses a similar example: http://makeapppie.com/2014/08/04/the-swift-swift-tutorial-why-do-we-need-delegates/
The answer to this question is kinda dependent on what you want the application to do... Do you want the User selections to persist even if the app is closed? If so consider using NSUserDefaults or CoreData. Otherwise store the data somewhere that does not get blown away (maybe the root view controller of your application). You could for instance implement the delegate pattern on the view controller with the table view and pass the values to the container view controller.. Just some ideas.
So you can use class NSUserDefaults to save small amount of data. If you want to have persistent store so you have to use Core Data that helps you store you data with scheme you provide.
If you just want to pass data from one view controller to another view controller so you just need use delegation pattern or you can use method prepareForSegue where you can pass some data as well but you can't store this way, just pass.
If you make your question more detailed you will get more explicit answer.
I am developing an app for Apple watch. I am pushing a interface controller from another interface controller ,how to send more than one object between controllers in Hierarchical navigation style?
you can make a new array of any object with your objects contents inside of that array:
var array = [AnyObject]()
array.append(youobject1)
array.append(youobject2)
After that you can user the send the context to the second interface with this array.
You could be sending an array or a dictionary that contains the several objects you want to send.
There are two ways to do so.
First: Pass an Array or Dictionary (according to jastrada - Sorry, because of my low reputation I can't vote up)
Second: Make a global structure or class (with static values) and when going from one to another, initialize the class and give it values, and get the values back in the second view.
Both of them will cause the expected results.
i know that the question sounds weird but i couldn't find a better way to put it or any solution online or with my current knowledge. I currently use a view controller + a table view where user enters a list of elements to filter my database (core data) and when he clicked the search button i fill tableview with filteredContent.
Now the question is this.
how can i show this filtered content simultaneously in the same viewController where user enter the input?
Is it possible? If yes how?
Assuming the user enters the filter via text field, make the view controller the text field's delegate and implement shouldChangeCharactersInRange:.
Each time the input changes, apply the search as if the search button was pressed.
But it seems the real question is how to do this without a vc transition. The answer is either convert to an NSFetchedResultsController, which does this kind of thing for a living, or do it yourself via the table view datasource methods.
If the latter, you'd keep an array that holds filtered search results. As the user enters search terms, you search core data, place the results in that array, then reload the table view. The datasource methods base their answers (numberOfRows, cellForRow, etc) on that array of filtered results.
I am building an app which mainly shows a tableview. In this tableview I have some custom table rows. The table rows are filled with data received from the server. I receive multiple kinds of data from the server. I will store it in arrays.
For example, I've got three kinds of arrays. Each is filled with different kinds of data received from the server. See below:
(NSArray*)carList_
(NSArray*)motorcycleList_
(NSArray*)bicycleList_
The actual program that I've got now, only shows the carList in the tableview. Foreach car in carList, there is a table row.
The thing that I've in mind to do is a little bit tricky. I want to add a tabbar at the bottom of the screen with three buttons. When I press the first button, I want the table to be filled with the carList. When I press the second button, I want to fill the table with the motorcycleList. And when I press the third button, I want to fill the table with the bicycleList.
As you can see, I will use the same tableview. I will only refill it with the data I want to see. Is this allowed in iOS? Cause I read something about that the tabbar is for multiple views, and I only want to use it for changing the data in my table. Only the fourth button I've planned for future development will open a new view. If it is not allowed, what is a good alternative do do it? Buttons maybe? I searched the web for what I want to do, but it seems that my idea has never been used before, I think my idea is not allowed in iOS.
At this moment I've a initialViewController (with almost no code cause it is used only to initialize some things of the server. It acts like a splash screen) and I've got a rootViewController which does the works. In the rootViewController I've got my Table with Table rows and it has the different arrays of data which are retrieved by a method that is called when the rootViewController is loaded.
I am programming without Storyboards, because I'd like coding and I want to understand how it works 'underground'. What is a good way to implement the tabbar if it is allowed what I want to do with it? I don't think a standard tab controller will work, because I am working with only one view.
Of course you can use the UITabBar solution. However this might be not very useful and this is not the idea behind the UITabBar. You can instantiate the same TableViewController vor each tab. In this case you can use the same class but you have up to the instances of this class when the user cycles through the tabs. This will be obvisously a waste of memory.
Your descriptions sounds like a UIToolBar with a UISegmetenControl in it might fit your needs better. You can also place it at the bottom of the screen and you will need just one TableViewController for your data.
UISegmentedControl is designed for switching between different data representations. It is also commonly used for switching between table datasources. But it often appears at the top of a view. Take a look at Top Charts tab of App Store app.
Tab bar is designed to present different views for each tab. Here are progress steps to achieve your result:
Use different instances of table view controller for each tab
Configure each instance for displaying one particular array, depending on tab position
Keep arrays in external (outside table view controller) storage, instances should have an access to it
It's better to preload data, while user is examining an active tab. Hence, load data outside of table view controllers, possibly in AppDelegate. Use notifications to update table view when data are available.
I have a UITableViewController that has the ability to save each row to a plist file. Currently when you press a detail disclosure indicator on the row it opens a separate UITableViewController with four static cells in two groups.
At the moment the data in these cells is just being saved in NSUserDefaults, but I'd like to be able to save them in a more robust manner (i.e. plist) and have each set of settings associated with its own row in the first table view controller.
Any help would be greatly appreciated.
Thanks,
Chris
Each of your groups can be saved as an array of dictionaries within your property list. Within each dictionary (or group), you may include various elements, least of which could be an array which would represent your 'related' items. This array could be a collection of simple values or even dictionaries themselves if you are working with a more complex set of data.
You may even take it a step further and use CoreData to create a nice relational object model.
Resources:
Property List Programming Guide
Core Data Programming Guide