mnbayan / AutocompleteTextfieldSwift

Simple and straightforward sublass of UITextfield to manage string suggestions
MIT License
290 stars 66 forks source link

XCode 8/Swift 3 Problems #42

Open cnpetrich opened 8 years ago

cnpetrich commented 8 years ago

The TableView never appears. I have debugged showing events firing correctly, but I never see any results appear after calling .autoCompleteStrings. Has anyone had any success after upgrading to xCode 8?

mnbayan commented 8 years ago

Hi @cnpetrich , Thanks for reporting this issue. I am currently working for the updates for XCode 8. I will investigate this issue and if confirmed, will provide the fix.

RahulM1987 commented 8 years ago

Hi @mnbayan , I am trying to get the tableview in Xcode 8 for Autocomplete textfield but it does not shows me when I set the storyboard for 6s or SE its not showing me subview which is tableview, however if is undone the changes and don't keep the storyboard specific it works.

Have you got the solution over it?

cnpetrich commented 8 years ago

Hi @mnbayan, any update on this? Still no luck from my side.

cnpetrich commented 8 years ago

After way too many hours spent troubleshooting and googling, it looks like it's a problem with how subviews are initialized in XCode 8. See here.

You can fix this by modifying setupAutocompleteTable function by adding the two lines below at the beginning of the function:

public func setupAutocompleteTable(_ view:UIView){ self.superview?.layoutIfNeeded() self.layoutIfNeeded() ...

p.s. I hate XCode 8.

ghost commented 8 years ago

Hi @cnpetrich. I modify setupAutocompleteTable function as you suggested, and yes - view is displayed, but in my case it appears in wrong place. Strictly speaking it appears above TextField instead of under.

In your project everything is ok?

cnpetrich commented 8 years ago

Yes, there were some additional changes I had to make to the function. Here is all of the modified code below. Please try and let me know if it works for you as well:

public func setupAutocompleteTable(_ view:UIView){ self.superview?.layoutIfNeeded() self.layoutIfNeeded() let screenSize = UIScreen.main.bounds.size let tableView = UITableView(frame: CGRect(x: self.frame.origin.x, y: self.frame.origin.y + self.frame.height, width: screenSize.width - (self.frame.origin.x * 2), height: 30.0)) tableView.dataSource = self tableView.delegate = self tableView.rowHeight = autoCompleteCellHeight tableView.isHidden = hidesWhenEmpty ?? true view.addSubview(tableView) autoCompleteTableView = tableView autoCompleteTableHeight = 100.0 }

@Przemex3000

ghost commented 8 years ago

Unfortunately your code didn't work in my project -self.frame.origin.y still returns negative values which resulted in view appears in wrong place. I created my own solution - maybe not so good but works. I invoke function setupAutocompleteTable from superclasss when all constraints are set and TextField frame returns correct position.

Thanks for help @cnpetrich