mnbayan / AutocompleteTextfieldSwift

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

Superview not available (TableView not showing) #3

Closed D-32 closed 9 years ago

D-32 commented 9 years ago

Not sure if it's the same problem #2 has, but I thought I'll write this down in case you want to take a look or if somebody else runs into this. I'm manually adding the view, so I'm using the initWithFrame method which then internally calls initialize (and setupTableView). The problem is that inside setupTableView you're adding the table view to the field's superview. But I'm obviously adding the field to my super view after the init call. Probably when using Storyboards the superview is already ready at that point.

Thanks anyway for your work, it's looking great in my project :)

rishimukherjee commented 9 years ago

@D-32 - Did you solve this problem in any way?

D-32 commented 9 years ago

My work around is to remove line 112 - 113, the setupTextField() and setupTableView() calls inside the initialize() method (AutocompleteTextfield.swift). And made those two setup methods public. Then in my code I add the textfield as a subview and call these two methods after addSubview.

mnbayan commented 9 years ago

@D-32 , thanks for reporting this issue. Although your fix will work fine, this is not good practice since i created this library to reduce work like what you did. In my fix, i modified setupTableView() to setupTableView(view:UIView?) and used the willMoveToSuperview(newSuperview: UIView?) to call initialize(superview:UIView?). This will make the tableview add itself right after the textfield has been added to its superview.

Hope this fix helps you.