Can you anchor a view in place? (or is there some other work around to preventing a view from being shoved by a UIDateTimePicker?) (iOS)

StackOverflow https://stackoverflow.com/questions/17711905

質問

I added a UIDatePicker programmatically, and I set it as the inputView and inputAccessoryView of a UITextField so that the date picker pops up instead of the keyboard when selecting the text field.

The date picker pops up; however, the only problem is, it shoves the rest of the view up, thus hiding the UITextField that is being changed (since the text field is at the top of the screen).

Is there any way to prevent this unwanted shoving from occurring? Or could I somehow anchor the view in place in the textFieldDidBeginEditing method and unanchor the view in the textFieldDidEndEditing method? (Note: I tried setting the view to the top of the screen in the textFieldDidBeginEditing method by doing self.tableView.contentOffset = CGPointMake(0, 0); however this did not do anything, and I think this is because this occurs before the view is shoved up)

If it helps, the delegate view is a UITableViewController. I am aware that UITableViewControllers are pretty restrictive, and maybe this is why it is acting up; however it wasn't letting me use static cells unless I put them in a UITableViewController so I had to choose it by default.

Thanks! Any help would be appreciated!

役に立ちましたか?

解決

I figured it out, you should only set the UIDatePicker as the inputView property of the UITextField NOT the inputAccessoryView property of the UITextField

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top