Make Multiple Selections in iOS App Based off Data from Parse Server - ios

My Parse server includes a class of songs. The data from this is Song name, and up to 6 different verses, where each is a string of text. It's set up to be like entry[#"SongName"] and entry[#"VERSE1"] leading all the way up to 6 verses. Some will have 6, others may only have 1.
The initial listing of the songs just shows the title in a PFQueryTableViewController. What I'd like to have happen is when a song is selected, show all the available verses, and let a user select all the verses they want.
I suppose I could set up a UIAlertController, and have it ask for each Verse the song contains if they want it, but this seems rather cumbersome, and I'd prefer a simple view showing the available options with a Radio button next to it, to mark a selection.
The setup I have so far is creating an Array of all of the options VERSE1 - VERSE6, and then getting a count of all the objects in there. Any help I could get pointing me in the direction to do this would be appreciated.
Again, I just want to figure out what would be the best way to present a label and Radio button for each object in the Array, allowing them to select multiple ones, even if not in sequential order. Something like a NSPopUpButton on the Mac where it would show all options from the NSArray, allowing them to select each one they want to include.
PFObject *entry = [self.objects objectAtIndex:indexPath.row];
NSArray *testingVerses = [[NSArray alloc] initWithObjects:entry[#"VERSE1"], entry[#"VERSE2"], entry[#"VERSE3"], entry[#"VERSE4"], entry[#"VERSE5"], entry[#"VERSE6"], nil];

Related

Swift 2.1 Selecting Options from Image Icons in a View Controller

If I wanted to have a screen with a number of options displayed via icons to present to the user to select from. What would be the best way to do this?
For instance if I had 6 different images with varying price ranges like $25 - $35, $35 - 50, $50 - $75 and so on and I wanted them to select one of these ranges, what would one suggest I use in this situation? A tableview? A collectionview? Is there a way to use a collectionview in this manner?
It is totally depend on your app requirement and UI. you can use tableview, collectionView, or scrollview.
you just need to manage the selection of the item. For that you should use NSArray of NSDictionary. Where NSDictionary having a key called selected which is set to true when item get selected. When any other object get selected you make a loop which make all object selected to false. and then set the selected object to true.

"Add to favorite" function

I need to have such functionality in my app as "add to favorite". I have UITableView with cells, where cell refer to DetailViewController that contains UIImageView. So I need to make such option, when user presses button on the DetailViewController, it goes to FavoritesTableViewController and saves it there.
I have looked through a lot of questions like this, but I can't figure out what to do as I am newly to iOS programming.
Should I use NSUserDefaults? How to use NSUserDefaults? And If I use it, how can I load saved data in another view controller?
I have not so many recipes (app of recipes), so can I use plist? Also I have UIImageView, is it possible to use plist with UIImageView?
If your recipes don't have identifiers, add them. This could be the name, or the associated image name, but it must be unique and it can't change. This needs to be stored in the recipe data (vehicular I assume is an array of dictionaries).
When you add a favourite, save the identifier in an array in user defaults. The identifier should be a string or a number. Each time a favourite is added or removed, get the array from user defaults, mutableCopy it, edit it and then save it back to user defaults.
For the favourites display, pass the full list of recipes (or load it) and then filter it to remove any where the identifier is not in the favourites array.

Filtering in UITableview

I am new to iOS app development.
I am developing an app which will show a list of companies.
This list is shown in a UITableviewController.
It has many labels like company name, their field in industry etc.
Once the list is displayed i want to give an option to filter based on their fields i.e.
listing all telecom industry or etc based on my login.
If the user is from a telecom industry i want to show all telecom related companies if user is from a service industry I want to show all service related industry and so on.
I want to give either a drop down on top or buttons or anything that will be easy to see and understand for the user to filter this out.
Please give me an ideas and if possible tutorials to achieve it.
Deeply appreciate your efforts,
Thanks
One way to do this, you can keep all the content in NSArray and you can put a set of buttons or a drop down list ( you can use NIDropDown) if you really want to have a professional look to categorize filters.
User will select any filter from the list and you need to filter the NSArray to extract the required information based on the action performed by the user on drop down list and reload the data in the UITableview.
follow these links to know how to create tables.
http://www.appcoda.com/ios-programming-tutorial-create-a-simple-table-view-app/
http://www.techotopia.com/index.php/Creating_a_Simple_iOS_5_iPhone_Table_View_Application
talking about filters , you can create two view controllers. On first you show all fileds that are present in a table view and user can select by tapping on anyone of them.
use delegate method tableView:didSelectRowAtIndexPath:. inside this method write the code to move to the next screen where details can be shown as per the user's selection.
tableView:didSelectRowAtIndexPath:
{
nextviewController = [secondDetailedView alloc]init];
[self.navigationcontroller pushviewcontroller: nextviewController Animated:Yes ];
}
now obviously you need a navigation controller that can be created in appdelegate method. What data has to be shown on next screen in table is up to you (on user's selection).

How do I display only a subset of a datasource in a UITableView?

I want to swap out the content of a tableview. The data source has elements with a flag that denotes whether or not they should be shown.
Ultimately, I want to be able to swap what is shown, depending on the flags. For now, though, I'll settle on an answer to the following.
How can my table display only a subset of the datasource?
I am not asking for a [tableView reload], which seems to be what most of my searches yielded. I want to show only some of the datasource items at a time based on a criteria (the flag, in this case).
As an example for clarity, here's a sample of the functionality.
We have 50 Friend elements in an array. It is the datasource for our table. When we load the app, all 50 friends are shown.
20 of those friends are marked as "Awesome" within the Friend class. When you tap the Awesome button, those 20 are shown in the table.
10 of them are marked as "Lame" within the Friend class. When you tap the Lame button, those 10 are shown in the table.
What methods do I need to look at to achieve that? TableView discussions are huge and I've been looking through bugs and errors without satisfying results, so far.
Keep two data structures. The first is the master set of data. The second contains just the data you want to display. Point the table to the second set of data.
Basically, when you want to reload the table with a different subset, create a new array, iterate the master data set and add just the objects you want to the new array.
SInce the second array just have references to the original objects from the master array, there is little extra overhead for this.
Update: To expand on the comment by Rob Napier, the master data structure I mentioned would be the "model" and the second data structure would be the data that backs the table's data source.
You can set up an NSPredicate to filter the values that will be returned by the fetchResults:
- (NSFetchedResultsController *)fetchedResults {
...
NSPredicate *predicate = [NSPredicate predicateWithFormat:#"flag == %#", #"Awesome"];
[fetchRequest setPredicate:predicate];
...
This will only return those records that meet the criteria of the NSPredicate.

Toggle showing/hiding child table cells iOS

I'm trying to create a UITableview that contains STATES and CITIES. To start with, I'd like the table to display only the STATES, with each value having a downward facing disclosure arrow on the right hand side of the cell which lets the user know it has values underneath it. If the user clicks the arrow, the table would expand to show the CITIES associated with the selected STATE. The user could then either select a CITY, or click on a upward facing disclosure arrow which would then "hide" the CITIES.
I've downloaded and reviewed Apples "Table View Animations and Gestures" example.
I was hoping someone might know a simpler way of accomplishing what I'm asking for.
http://developer.apple.com/library/ios/#samplecode/TableViewUpdates/Introduction/Intro.html
Good Job on explaining exactly what you want to do. This is how I would tackle this, I figure it would be easier to explain it without giving you meaningless code and answer any coding concerns you might have after.
I would set up the table view data source to be an array of arrays. The idea would be that every index in the array would represent a state and therefore contain a number of cities, hence ever index contains an array (array of cities). The parent array(of states) will be empty at the beginning, but the arrays(of cities) that will later fill it would be populated with the appropriate cities.
I would then set up the table view to contain sections (I a tempted to put code here, but read along). The sections would represent the cities. You can then fill out the table view with sections using (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section delegate. On the first run you can fill the actual table with one cell per section (maybe with the word "expand" or "more" and your down arrow). When the user touches that cell you can use the didselectrowatindexpath to know which section was touched (the indexpath object contains the section), now that you know which section it is, just modify the data source by adding the array of cities for that section of the array of arrays (parent array) and update the tableview.
This essentially gives your tableview an according style and feel. It is very easy to implement but requires a little bit of code. I have done this and am willing to provide the code you might need, the trickiest part would be to update the tableview in the correct way.
EDIT CODE:
I did a simple example following above explanation. The code is on Github , feel free to ask any questions about it.
I think a better way to represent this information would be to have a UITableView containing the states with each state showing a tiny arrow pointing to the right. Then, when a user clicks on the state, load the next UITableView that shows all of the cities in that particular state. Using a UIViewController for pushing the City list will allow users to easily return to the States list.
This approach will make much more sense to iOS Users, because this is how they expect Tables to work.
There are many tutorials explaining how to use UITableView. Here is a link to a site with many UITableView tutorials. The tutorial I linked to explains pushing a UIViewController on to the stack so that there is a simple back button back to the State list.
Normally such thing is done by seguing to another view and showing more details about cell.
What you want you could achieve by actually making custom UITableViewCell which would contain UIButton with arrow image and UITableView. In case button is clicked for the first time you could reload your cell and create inner UITableView which could show cities. Another click would simply reload cell again and not return inner UITableView at all. You also need to keep selected state somewhere because you may have to reload previous cell and hide inner table in case arrow in other cell is clicked.

Resources