Reputation: 255
alright, the title might be a bit misleading, but I wasn't sure how to properly describe it. But anyways, here we go:
I've got a UIViewController
(within a UITabBarController
) which contains a UITextField
. When pushing this ViewController on to the Navigation Stack I've got to do some Work with the UITextField
:
I put String inside the UITextField
and process them (again, this all happens when the ViewController loads (currently inside the viewDidLoad()
method)). In order to process them, I need to calculate the Rectangle which the String occupies inside the UITextField
.
var pos1 = tagTextField.positionFromPosition(tagTextField.beginningOfDocument, inDirection: UITextLayoutDirection.Right, offset: 0)
var pos2 = tagTextField.positionFromPosition(tagTextField.endOfDocument, inDirection: UITextLayoutDirection.Right, offset:0)
var rectForButton = tagTextField.firstRectForRange(tagTextField.textRangeFromPosition(pos1, toPosition: pos2))
Exactly here is my problem. When doing this while the view is loaded, the tagTextField contains text, but does not show the text, therefore the rectForButton does not have any width.
My thoughts on this were, that I have to run this on a later point (I tried viewWillAppear()
, viewDidAppear()
, etc. but nothing worked).
Anybody any idea how to solve this? Basically to sum it up, I need a method which is called after everything concerning the UIViewController has happened.
Not sure if this of any significance, but I work with Swift and XCode 6 (the latest release of both)
Thanks
EDIT:
Apparently tagTextField.beginningOfDocument is nil, whereas tagTextField ist not nil. Anybody any ideas how to solve that?
Upvotes: 2
Views: 448
Reputation: 15464
Does your textfield comes from interface builder? You can try it in viewDidLayoutSubviews function.
Upvotes: 3