Wednesday, 15 May 2013

ios - How can you make a UITextfield give suggestions and return your selection using Swift? -


The application I created needs to use the search bar for comb through the array and what you write There are suggestions for this. When the suggestion appears from the array, then you need to select it and return it to UITextField .

I have done so many research in how I have done this, but no luck has happened so far, I have found some things in Objective-C but still does not help me.

I know that this is a little bit on the internet to do with a UISearchController , however, UISearchController do not give me what I need, I need the initial search field Not in the UITableViewCell , not at the top of the page, if it comes It will work if you can change the initial search field, but I have done research that is not possible.

If this is possible, can you please tell me that after all this is what I wanted.

So my code is so far UITableview with two sections, the first of which is the textfield as I suggest appearing as typing I want to use the second section. I am having difficulty in inserting new lines and displaying suggestions based on my array, not only by me but also with many of our course partners, any help would be greatly appreciated because of their final graduate projects Along with the same problems.

Here is my code

  Import UIKit class ViewController: UITableViewController {var stations: [string] var section title: [string] @ IBOutlet weak Var searchField: UITextField! (In the "London") stations .append ("Poole") section title = [string] () sectionTitle (init) (stations: [bn] .append ("search") sectiontelt.apend ("result") super intrate (encode: adcoder)} overdried funk viewDidload () {tableView.rowHeight = 80; SearchField.delegate = self super.viewDidLoad () // Make an additional setup after loading the view, usually from a nibb. } Override Funk Receive Memory Warning () {super.didReceiveMemoryWarning () / any resources that can be redone. }} Extension View Controller: UITableViewDataSource {override func numberOfSectionsInTableView (Table View: UITableView) - & gt; Int {return sectionTitle.count}} Extensions View Controller: UitViewDelegate {override func tableView} (table view: UITableView, didSelectRowAtIndexPath index path: NSIndexPath) {tableView.deselectRowAtIndexPath (indexPath, animated: true)} Override func tableView (tableView: UITableView, titleForHeaderInSection section : Int) - & gt; String? {Return section title [section]}} Extension View Controller: UITDefined Delegate {Funka Textfield Shawled Retrain (Textfield: UITFixified) - & gt; BULL {println ("search") // Loop though the stations array // path = NSIndexPath (forRow: 1, address: 1) // path = = [path] // tableView.insertRowsAtIndexPaths (path, with three-dimensional animation: automatic. ) Cell = tableView.cellForRowAtIndexPath (NSIndexPath (forRow: 0, in Address: 1)) Cells? .textLabel? .text = searchField.text searchField.resignFirstResponder () returns true}}  

I 've been given great attention to the fact that my code needs to be focused, because now I would be happy if I could insert rows in the second part for each part of my part, i.e. loop through the array and insert the new line for each item.

  View Detail Controller: UITableViewDelegate {Override Function Table View (Table View: UITableView, didSelectRowAtIndexPath Index Path Path: NSIndexPath) {tableView.deselectRowAtIndexPath (indexPath, Animated: True)} Override Func tableView (Table View: UITableView , TitleForHeaderInSecti section: int) - & gt; String? {Return section title [section]}} Extension View Controller: UITDefined Delegate {Funka Textfield Shawled Retrain (Textfield: UITFixified) - & gt; BULL {println ("search") // Loop though the stations array // path = NSIndexPath (forRow: 1, address: 1) // path = = [path] // tableView.insertRowsAtIndexPaths (path, with three-dimensional animation: automatic. ) Cell = tableView.cellForRowAtIndexPath (NSIndexPath (forRow: 0, in particular: 1)) cell? .textLabel? .text = searchField.text searchField.resignFirstResponder () returns true}}  


No comments:

Post a Comment