How to add a search bar to pick sorted data from Picker view - iphone

Hi guys i have added a picker view to pick areas from it.This picker view contains more than 200 areas so it is difficult to scroll and select from picker view.
Is there any way to add a search bar and connect it with picker view?
I tried doing this by using search bar delegate method by overriding it but i am not able to achieve the goal.
So please help me so that i can do it or if any another way possible then also tell me.

Picker view is for small number of selection. Use table view instead for such big number of options.
Just to back up my statement, the Apple Human Interface Guideline says
Consider using a table view, instead of a picker, if you need to display a very large number of values. This is because the greater height of a table view makes scrolling faster."

I agree with barley that the PickerView is an awful vehicle for large selections; if at all possible to use something else, that would be appropriate and best, but having said that:
The YHCPickerView looks promising from:
http://code4app.net/ios/PickerView-with-Search-Bar/509fb2e86803faf25c000000
From a cursory view of that class, it appears that it has several different and distinct UI elements, the text field for collecting search criteria, the button for enacting the search, and the basic picker view. The search criteria simply and directly filters the picker data/model when the button pressed event occurs. That way you are simply editing the actual data from the picker.
If you handle each of these separately it should make it simpler to create what you want, since you only have to handle the basic functions and delegates of each individual UI element and linking together their effects rather than trying to hijack an existing delegate.
-Cheers

Related

How to build this screen in iOS?

I'm new to iOS development and am trying to build something like the screen below:
If I was doing it in Android, I can easily build the above UI in a few minutes. However, I don't know how to go about it with iOS.
I understand that the whole ViewController can be embedded in a navigation controller, which produces the title bar above. What about the bottom part though? I'm thinking of using something like a grouped UITableView but I'm not sure, since every cell will have very different contents:
A search bar, perhaps a subclassed UISearchBar, which I also don't know how to customize--the Search button at the right is required but isn't in the default UISearchBar. When the user taps on it, the UISearchBar must be translated to the navigation bar, no need to display a UITableView of suggested results. I don't know how to do that, too.
A button that, when tapped, flies in a modal from the bottom (I imagine it to be another ViewController with a grouped UITableView), to allow the user to choose from defined locations. Once selected, the modal closes and the button text is replaced with the selected location. This sounds much easier to do.
A header ("Item categories") and the list of categories, which may change in number. If the parent isn't a grouped UITableView, I think this part can be a UILabel and a non-scrolling UITableView with a height that changes depending on how many cells it has. If there are plenty table cells that don't fit given the screen's height, everything below the navigation bar can be scrolled vertically. That, I also don't know how to do.
If anyone can just guide me to what native iOS components I can use to build the above screen, and maybe a couple of tutorials to the things I just said I don't know how to do, I'd appreciate it.
You said it right .All the basic info you need is with you.
To build a searchbar like that i dont think you have to subclass it.
Bottom comprises of tableview.
Actually these Questions are seperately available in SO itself.So search seperately for your needs and you can achieve whatever you want
One basic principle : You cant achive anything by just thinking.Trying and get to it and if you have any issues look forward at it.All the issues will have an answer on the way.
Lots of components you need there.. Search Bar, UIPickerView and UITableView. I would like to give you some pointers.
1) You can refer http://www.appcoda.com/how-to-add-search-bar-uitableview/ for Search bar
2) When clicking on the Button, you can bring up a UIPickerView instead of another controller. For that you can refer http://www.techotopia.com/index.php/An_iOS_5_iPhone_UIPickerView_Example
3) You can use a normal Tableview with a single section, configure the section header to display Item categories.
You are asking too much to ask how to do every component of your UI. I will just answer a little.
Yes, a grouped table view is a good design. I am using a grouped table view for varying types of input. I have an actual table, with rows that can be added, and deleted, and contain an editable text area. Then I have three groups that only really show one piece of content each: two are sliders and one is a switch.
For choosing the location, pushing another view controller on your navigation stack would be the more typical way to handle it. You will save some effort that way, with some buttons and behaviors built in, but a modal view controller is not much harder. I'm not sure if you can make a navigation view fly in vertically, but does your app have to be frame-for-frame identical to the android version?

UITableView display search results in separate tableview

I am implementing real-time searching of a UITableView. I would like to display the results in a separate table view (in it's own UITableViewController class). Is there a way to simply replace one tableview with another once the user begins typing in the search bar?
Refer to UISearchDisplayController. It will surely provide what you require :)
Create two tableViews, tableList and tableSearchResults. Also declare one more tableView namely, tableCurrent. Initially make tableCurrent to point to tableList, then load the objects into tableCurrent. You can use this (tableCurrent) to display contents and handle selection events.When user fishes searching, assign tableCurrent to tableSearchResults, and then load objects from search results array. This will make two table views, one for Listing and other for search reasults...
Happy programming
There is little reason to use two actual tableViews, if only one is visible at a time. You could just change the .dataSource and .delegate properties. (If they are sized and styled the same anyway.)

iOS UI - how to tell user that there are no data in table view?

This is the situation:
A user filters a database by selecting keywords from a list, then presses "search". This pushes an instance of a UITableViewController subclass onto the navigation stack.
In the viewWillAppear: method, data are fetched from Core Data and stored in an ivar, ready for the table view's data source and delegate methods.
So far so good.
The UI problem arises when there are no results.
This simple architecture means that an empty result set yields an empty table view with no explanations.
It would be good for the UI to tell the user something like "Your search gave no results, please try with fewer keywords".
My question is this:
What is the best way to provide relevant feedback to the user, without having to change the architecture too much?
I was thinking about using the table header, but what do my esteemed colleagues here think?
Using the table header is not a bad option. You can go for that. You can also try other options like showing the info in a simple label or perhaps even an alert. But personally I wouldnt recommend the alert.
U can show that in UIAlertView.
You could add / show a UILabel to your view that says "No search results" (or something like that) when the table does not contain any data.
After fetching the result from core data... just count the number of rows in the result and then before displaying Table View just check if Count>0 then only go for table view ... else just display UIAlertView... this will save u from unnecessary display of UITableView
You can put AlertView when your ivar is empty and in alert button index return to the main view from where you are entering your search. This is the best way for you without changing your architecture.

How do I make an editable detail view on the iPhone with a grouped UITableView?

I want to make a grouped TableView similar to the Apple iPhone contacts application.
I need a lot of standard fields which can be edited, but I would only like them editable once the edit button in the navbar is clicked.
This has been bothering me forever that I could not find a good tutorial.
Thanks in advance.
This is not easy. I just built the same thing because there is nothing available from Apple. I ended up creating a single table cell with a UILabel and a UIView on it. The UILabel is for when the cell is in read mode, and the UIView is for editing. The UIView contains a number of UITextFields. These are the individual fields. I also had to implement drawing code to draw the lines between the fields. Then I had to come up with the code to pass in an address object, load it into the fields, format the text for the label, switch in and out of editing mode (with animation), and finally handling saving of changes and canceling. As yet it doesn't handle tapping the address type to select that from a popup list, but I have most of the code in place for the rest.
This could have been done using individual table view cells for each field. But then you can't select the whole thing the way it does in contacts and adding and deleting addresses becomes trickier.

Changing number of button rows in UIAlertView using public API's

In a UIAlertView I need to align buttons into rows so that there are either 2 in each row or 3 in each row. This is for an appstore app so I need to use documented methods. So obviously I can't use setNumberOfRows: for this. Suggestions on how I could achieve the same effect?
You can't customize UIAlert to any meaningful extent.
In any case, it sounds like you don't want an alert view but rather sheet or a modal view.
UIAlert is restricted for a reason. It's supposed to present a simple, standardized (and easy to call) view to draw the users attention to a specific issue. You don't want to use it for complex choices.
If you create your own view and present it modally. It will popup above the other views just like an alert but you will be able to customize its appearance and behavior as you wish.