Manually scrolling UITableViewController when a UITextField becomes first responder - iphone

Harrr pirates!
I'm trying to make a data entry screen using a UITableViewController. It contains a grouped table view with two sections, each with a few (2 and 4) rows with a UITextField inside them.
When any of the UITextFields become first responder they scroll into view automatically. Great, you would say, but I want to scroll the whole section into view, not just the row containing the UITextField that became first responder.
I don't allow the user to scroll the UITableView by hand and I know to what position it should scroll to display correctly. However, I can't get my UITableViewController to stop automatically scrolling the UITextField into view for me.
Searching StackOverflow I can find a lot of questions about how to resize the UITableView when the keyboard appears, but this doesn't stop the automatic scrolling.
Any suggestions? Your help would be much appreciated!

TableView is basically an extension of scrollView therefore if you want to do the scroll yourself you should use the scrollview API.
Set the contectSize property to the size of the screen without the keyboard and the contentOffset to the location on the table you want to scroll to

Related

View with uitableview, tabbar and more objects

I'm developing an app and I need a view with these elements:
- UITableView
- UITextField and UIButton
- TabBar
As you can guess, I am developing a chat, but when I put the elements in the .xib, I can't show de layer: UITextField and UIButton. If I put them without a view, they dont appear.
If I put a view under the table, and in that view I put the text and the button I get this error: http://pastebin.com/CKfxijz9 (I put the error there because it's to long)
Thanks in advance
There are some ways of dealing with that, depending on how it should behave. Some of them are:
Provide a table footer or header view that holds the button and
the text field.
Nest the table view into another view. The table
view and the view containing the button and text fielt are on the
same level within the view hierarchy. They are rather siblings than
sub- and superview to each other.
Use a UISlider instead of a table. (However, I personally would use the table.)
Here's an approach I've used in the past (not sure if it's best practice, but it works).
Add your button and textfield to a new view (let's call it, bottomView)
Add bottomView to the superview of your tableview
Set the frame of your bottom view so that it fits to the bottom of the screen (this will make it so your tableview will scroll, but keep your bottomView always attached to the bottom of your mainview)

Implementing a dynamic height on UITableView

I have a UITableView embedded in a UIViewController. The TableViewCells are rows for the user to select something, so when they touch it a checkmark appears, heres where my question comes in:
I dont want the UITableView to scroll in its window, I want the TableView to grow with the items it contains. Do I need to put a scroll view on the UIViewController and then the TableView on that? Or will the ViewController scroll if the content is bigger than the View?
Also, Im not even sure where to start with changing the height dynamically of the UITableView, everywhere I look its about changing the cell heighets dynamically.
Please Help! Thank you!
self.tableView.scrollEnabled=false;
stops the scrolling
self.tableView.frame=CGRectMake(0, 0, (float)width, (float)height);
sets the size of your tableview
But I don't understand why you want to stop tableview scrolling and to scroll the whole view....

Prevent keyboard from moving textview in UITableView

I have 2 cells in a group in a tableview, the first has a textview in it, (2 lines max). When the user selects the textview, the keyboard appears and moves the textview up from under the keyboard. the second cell only appears when the textview has focus.
However the second cell is still hidden by the keyboard, I have tried to the various methods that scroll the tableview, but the result is always jerky, with the table moving up and down rapidly. Probably because its inserting a row, scrolling up for the keyboard and me trying to make it scroll up even more all at once.
How can I prevent the keyboard from moving scrolling the table view at all, so that I can do the scrolling myself exactly how I want it, and avoid the ugly fight between the two methods.
Did you try this method by setting scroll position to UITableViewScrollPositionTop ,if this not work ,just make your second cell that with textfield :)
- (void)scrollToNearestSelectedRowAtScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated
Use a UITableViewController instead a UIViewController (for the ViewController where your UITableView is placed). That will solve the scrolling issue.
If not possible, you have to scroll by your self (pain in the ass).
See: Making a UITableView scroll when text field is selected

Let tableview's last cell scroll to half way up the screen

I have a tableview with custom cells. Each cell has a UITextfield. When the last cell's textfield is clicked, the keyboard pops up and covers it and the table view won't scroll up any further. Is there a property of UITableview that can be set so that the last cell can scroll to half way up the screen?
Thanks in advance
There are a two ways to approach this (that I can think about off the top of my head):
You can use the tableFooterView property of UITableView to set an arbitrary, empty view to be about half the size of your table.
You can add empty cells to the bottom of your table
Both of these approaches will accomplish roughly the same thing, but using the tableFooterView property is probably your best bet.
see Making a UITableView scroll when text field is selected for a list of solution..
Also basing your view controller from UITableViewController (since you say its a table) will provide all this functionality automatically!

Unwanted automatic scrolling with UIScrollView and UITextFields as subviews

The "too long; didn't read" version: Is there any way to disable the automatic scrolling behaviour of UIScrollView when telling a UITextField to becomeFirstResponder?
I have a scroll view with paging enabled and several views as subviews, each subview being controlled by its own view controller. Each subview has a UITextField.
The requirement is that when a page is scrolled into view, it's text field should become first responder.
This is fine when using finger swipes to scroll -- I use the scroll view delegate method scrollViewDidEndDecelerating: to know when scrolling stops and a page is in view, I can tell the text field to become first responder.
However, when the scroll view is "autoscrolled", as in when telling the scrollview to scrollRectToVisible:animated:, the scroll view delegate method for deceleration isn't called. I use this method when scrolling newly created pages into view without the user's interation, or when the user taps the UIPageControl.
My solution was to simply set the first responder status of the text field before telling it to scroll into view - but it seems that telling a text field that is in a scroll view to become first responder causes the scroll view to automatically scroll it into view.
I assume this is behaviour used when putting text fields in table view cells (since table views are scroll view subclasses). If you set up a small test app, with a table view, and a text field within a table cell, if the keyboard would obscure the table view cell when it becomes first responder, the table view will automatically scroll it to be visible.
I don't understand, though, why this behaviour occurs in my example, where I'm not using a table view - just a plain scroll view.
I should also mention that my scroll view has vertical scrolling disabled and only scrolls horizontally.
I have tested in another test app that puts text fields as direct subviews of a scrollview (no view controllers or container views) and the same happens. If you tell a text field that is offscreen to become first responder, the scroll view with automatically scroll it for you.
This wouldn't normally be a problem, but it seems to screw up the paging of the scroll view. When I scroll with my finger, each view bounces and is centred properly. But when I scroll a rect to be visible with animation and tell a text field to become first responder, scroll view seems to become conflicted with itself and the view is only scrolled part of the way into view, and isn't centred.
Then, if I touch a view using my finger (not swipe, or even move), the scroll view jumps back to the first page.
My current work around for all this silly auto scrolling behaviour is to use an NSTimer to determine when to update the first responder.
I do the manual scrolling in code using scrollRectToVisible:animated and then after 0.3 seconds, call my method to update the text field to be first responder. (0.3 seconds was trial and error, trying to see which seemed to be the smallest amount of time to allow for the animation but still be long enough not to cause the conflict with the scrollview.
As you can see, this isn't elegant, and is likely to break.
Is there any way to disable the automatic scrolling behaviour of UIScrollView when telling a UITextField to becomeFirstResponder?
Call becomeFirstResponder, then right away, set the contentOffset of the scrollview to its current position..
[textField becomeFirstResponder];
[scrollview setContentOffset:scrollview.contentOffset animated:NO];
Not an answer to your question, but it should fix the problem:
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
{
// Make the text field first responder...
}