Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift MPGTextField autocomplete in tableview cell

I can't see suggestions when typing.. i have tableview cell and textfield in it.

I'm using MPGTextField library, swift version(swift 2 supported).

Any solution for this?

enter image description here

Code:

@IBOutlet weak var articleField: MPGTextField_Swift!

override func viewDidLoad() {
    super.viewDidLoad()
    articleField.mDelegate = self
}

func dataForPopoverInTextField(textfield: MPGTextField_Swift) -> [Dictionary<String, AnyObject>] {
    return articles
}

func textFieldShouldSelect(textField: MPGTextField_Swift) -> Bool{
    return true
}

func textFieldDidEndEditing(textField: MPGTextField_Swift, withSelection data: Dictionary<String,AnyObject>){
    print(data["CustomObject"])
}
like image 649
Mirza Delic Avatar asked Nov 13 '15 11:11

Mirza Delic


2 Answers

In the MPGTextField-Swift.swift you'll find a function provideSuggestions()
In this function you'll find a line

self.superview!.addSubview(tableViewController!.tableView)

Replace this line with

//BUG FIX - SHOW ON TOP

//self.superview!.addSubview(tableViewController!.tableView)

let aView = tableViewController!.tableView
var frame = aView.frame

frame.origin = self.superview!.convertPoint(frame.origin, toView: nil)
aView.frame = frame

self.window!.addSubview(aView)

////

I've forked MPGTextField repository, made necessary changes for demo purpose.
You can find my repo at https://github.com/rishi420/MPGTextField

Note: This repo needs Xcode 7.1.1 to compile. Feel free to contribute. :-]

like image 190
Warif Akhand Rishi Avatar answered Oct 12 '22 23:10

Warif Akhand Rishi


I can't really tell what's going on. Is the autocomplete box showing but just cut off at the bottom of the tableViewCell? If so, try setting clipsToBounds to false on the tableViewCell, and maybe even its content view too.

Touch events are not by default recognized for areas outside of a view's frame. To route the taps to the suggestion, you'll have to subclass the tableViewCell and override hitTest

like image 22
Austin Avatar answered Oct 12 '22 23:10

Austin