I have searched SO, but could not find any helpful answer.
I have a storyboard with three (3) textfields, to these textfields I want to make autocomplete textfields.
Am creating tableviews like this
let tblNumbers = UITableView(frame: CGRectMake(16,140,74,200), style: UITableViewStyle.Plain)
var arrStrNo = [String]()
var arrStrNum = [String]()
let tblYears = UITableView(frame: CGRectMake(120,140,74,200), style: UITableViewStyle.Plain)
var arrStrYr = [String]()
var arrStrYears = [String]()
let tblType = UITableView(frame: CGRectMake(222,140,74,200), style: UITableViewStyle.Plain)
var arrStrTyp = [String]()
var arrStrType = [String]()
So programmatically am showing tableviews to just below textfields in shouldChangeCharactersInRange
.
table.reloadData()
In storyboard am setting constraints to textfields, now am wondering how can I set constraints to these tableviews, so it should be exactly below the textfields in all size screens.
Programmitically, am trying like below to set constraints to tableviews in viewDidLoad
method but its not working
func setConstraintsToYearTableView(){
let topConstraint = NSLayoutConstraint(item: self.tblYears, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Top, multiplier: 1.0, constant: 190)
let leadingContraint = NSLayoutConstraint(item: self.tblYears, attribute: NSLayoutAttribute.Leading, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Leading, multiplier: 1.0, constant: 120)
let trailingConstraint = NSLayoutConstraint(item: self.tblYears, attribute: NSLayoutAttribute.Trailing, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Trailing, multiplier: 1.0, constant: 0)
let bottomConstraint = NSLayoutConstraint(item: self.tblYears, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Bottom, multiplier: 1.0, constant: 0)
NSLayoutConstraint.activateConstraints([topConstraint, leadingContraint, trailingConstraint, bottomConstraint])
}