Performing Auto-Complete on UITextField in Swift for iOS - ios

I'm totally new to App design for iOS. I am designing an iOS app with Swift. I have a RESTFul service that returns a list of Cities based on a partial string query. My webapp uses Jquery-AutoComplete to perform the operation and it works great, I was wondering how I can achieve the same drop-down list look with Swift.
Here's how I retrieve the data. If the size of UITextField is greater than 3 characters, my App Starts sending the content of the UITextField to my RESTFul Service and get back the list of cities that start with those characters (My service returns the top 10 matches).
My challenge is, how can I show a drop-down under the UITextField just like JQuery-AutoComplete list ?

From comments above:
I would use a UITableView underneath your UITextField, which you would then populate its data source with the response from your web service.
does it integrate seamlessly ? I mean when there is no data it hides automatically or I have to track its visibility ?
You can set the hidden property of the table view depending on whether there is anything to display from the web service response. If there is no data set hidden to TRUE, if there is data set it to FALSE and use the reloadData method to reload the table views data source.
Thanks. So one last question, If I have stuff under the UITextField, when I set the visibility of UITableView, is it going to appear over the background and elements under the UITextField or it's going to push them down and rearrange the UI ?
This all depends on how you set up your UI. I would add the table view as a subview of the main view which would add it above any other objects. Again, however, this would depend on how the rest of the UI is set up. You can use the insertSubview: aboveSubview: method to make sure the table view is above all other views. Setting the hidden property of the table view to TRUE will not have any affect with regards background of objects underneath.

Related

creating a scrollview with data coming from database and variable number of elements for ios

So I was trying to create a sample ios application. As I am designing the app UI with the storyboard (and not coding), I find Xcode really hard to understand.
what I want to do is I added a scrollView to the view controller. now what I want to do in the scrollView is simple.
I want my scrollView to have buttons (vertically stacked) and it does some action on the basis of the data it is getting from the database. let's suppose it is getting links from the database and on a click of those buttons those links open. now the data may contain 10 links, or 20 links .. basically, we want it to be according to the database.
now if I was designing the UI programmatically it would look something like
ScrollView{
for loop...{
button("for example name coming from the database"
}
}
or atleast this is what I know of.
so how to do the same with storyboard ?
like we first take it's refernce to the uiViewController class.. and then ?
You need to add buttons programmatically if they are created dynamically depending on external non static data. Create new UIViewContoroller class and implement it with connecting storyboard file, the easiest would be to add buttons inside some kind of UIStackView which is inside scrollview imo, or by using UITableView if there are significant number of links to display.

Best practice for displaying empty/non-empty results for a search in iOS xcode

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.

Using a tabbar for controlling the tableview data in iOS without using storyboards

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.

Alternate text for empty UITableView?

I am using a UITableView to display some data which the user can filter. If a certain (perfectly "legal") combination is selected, all data is filtered out (hidden). I would like to display some text stating that no results were found and to please modify your filters.
Does anything trigger when this occurs that I can hook in to?
Or will I have to manually check for an empty data set and create a custom view to display my text? (I was thinking of creating a blank cell and using that footer? Hoping for something more elegant...)
I found a similar question, but the solution is not what I am looking for: Handling empty UITableView in UITableViewController
Also, I have an Android programming background and use this exact feature frequently, I would be surprised if Apple didn't do this as well!
Put a custom view with your error text message behind the table. Then when there is no data to be displayed set table.alpha=0.0 (or table.hidden=YES), while when you have this data available set table.alpha=1.0 (or table.hidden=NO).
You can do the control on the "OK" button (or equivalent) of the filter.

Monotouch.Dialog: Enable Selection in UITableView

Using MonoTouch.Dialog I create a table of values.
When the user clicks a row, the row should flash blue as per normal.
How do I enable this in MonoTouch.Dialog?
MonoTouch.Dialog supports the flashing behavior for Elements that can actually respond to events (like the StringElement when it has a tap-handler attached) or other elements that need to respond to the user's interaction.
This is done by setting the SelectionStyle property on the cell to UITableViewCellSelectionStyle.Blue
Most of the cells that do not respond to user's input have the value in MonoTouch.Dialog set to None. You can either change the source code to make it use Blue everywhere, or make sure that you are using the right Element for the right use case.
I blogged about some design patterns for building Elements recently, if you want to roll your own:
http://tirania.org/monomac/archive/2011/Jan-18.html

Resources