开发者

Make UITextField inside a table view visible scrolling

开发者 https://www.devze.com 2023-03-03 21:11 出处:网络
I have a UITableViewController, a bunch of sections and rows, and for each row I added a UITextField as a subview, right aligned in the row itself.

I have a UITableViewController, a bunch of sections and rows, and for each row I added a UITextField as a subview, right aligned in the row itself.

If the users taps on the row, I locally save the indexPath, make the corresponding text field become the first responder and finally, when the keyboard appears, I make the table view scroll so that the row remains visible.

开发者_如何转开发

I am facing the problem to obtain the same behaviour when the user taps the text field instead. In this case the didSelectRowAtIndexPath: method isn't called, so I do not know how to tell the table view to scroll to make sure that the "selected" row is still visible.

Probably the whole process is not correct. Do you know a way to solve it?

Thanks a lot!


I'm not absolutely sure about this, but...

Set the userInteractionEnabled property of the UITextField to NO. This way, the touch goes "through" the control, tapping the UITableViewCell. When didSelectRowAtIndexPath: is called, set the userInteractionEnabled property of the UITextField to YES. When the editing is complete, change it back to NO.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号