UITableViewController scroll default behaviour - ios

I'm using a UITableviewController with textField and text view in cells. By default when i click on a textfield the tableviewcontroller scroll the content up for let me se the content of the field. This default behaviour is very useful, but i've implemented a toolbar with a done button (inputAccessoryView) when i edit the textView. This is a problem when I switch from editing the textField to editing the textView, because the toolbar of the keyboard is just above the textView.
I've tryed a lot of solutions but nothing work for me. I've tryed something like this: https://developer.apple.com/library/ios/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.html
but doesn't work for me because i suppose this behaviour is already implemented in UITableViewController.
PS: the UITableViewController was created with Interface Builder. I don't know if this information is useful.

If you set up your UITableViewController to implement the UITextViewDelegate protocol, then you can know when you begin editing the textView by implementing this method:
- (void)textViewDidBeginEditing:(UITextView *)textView
{
//then you can scroll the tableview up so you can see the textView
[self.tableView setContentOffset:CGPointMake(0, /*height of your toolbar*/) animated:YES];
}

Related

UISearchbar Hide/Show Issue in UITableView

I have UISearchBar on my UITableView set as its tableViewHeader using InterfaceBuilder. I have hidden it under the UINavigationBar using
self.tableView.contentOffset = CGPointMake(0.0, self.searchBar.frame.size.height);
in my ViewWillAppear method. The problem is that if I go to the detailView and come back to this TableView, if the TableView has more than the screen visible cells, it works fine and hides the SearchBar as it is suppose to do, but if there are less than screen visible cells (i.e. tableview has 0 - 4 cells) then the SearchBar doesn't Hide.
Does anyone know why this is happening?
thanks in advance

UITextField as child of it's own inputAccessoryView

I'm attempting to duplicate a UI similar to Messages. I have a UIToolbar pinned to the bottom of the view in a xib. On that toolbar is a UITextField. I've set the UITextField's input AccessoryView to be the UIToolbar. When I click on the UITextField, it snaps into position, but there's no keyboard underneath, just blank as if the keyboard was hidden. When I click on the UITextField a second time it animates with the keyboard. I've attempted to become it's delegate and all the other suggestions in other SO posts, but no luck.
#implementation ChatViewController {
IBOutlet UIToolbar *_keyboardAccessory;
IBOutlet UITextField *_textField;
}
- (void)viewDidLoad {
[super viewDidLoad];
[_textField setInputAccessoryView:_keyboardAccessory];
}
It will be simpler if you don't try to make the toolbar be the text field's inputAccessoryView. Just animate the toolbar up with the keyboard appears, and down when it disappears.
Everything you need to know to do this animation is documented in “Managing the Keyboard” in the Text, Web, and Editing Programming Guide for iOS. You can also find answers on stack overflow describing the process. here is an answer describing the process step-by-step with all the code.

Keyboard not showing-up for UITextField in UITableViewCell in iOS 6.x

Working on iPhone/iPad application,
Problem: Keyboard not showing-up for UITextField in UITableViewCell in iOS 6.x, but same code works fine on iOS 5.x
We developed a UIViewController, in which we tableview is created. In this tableview, we have added textfield cell. So textfield shows the cursor, but it doesnot bring-up the keyboard, nor the cursor moves. (Every thing works fine on iOS 5.x)
UITableView *localTable=[[UITableView alloc]initWithFrame:tableFrame style:UITableViewStyleGrouped];
self.tblScheduleBasicInfo=localTable;
[localTable release]; //release the localTable
enter code here
#interface CustomTextFieldCell : UITableViewCell {
UITextField *cellTextField;
}
CustomTextFieldCell *tfCell2;
tfCell2=(CustomTextFieldCell *)[tableView dequeueReusableCellWithIdentifier:textFieldIdentifier1];
if(tfCell2==nil)
{
tfCell2=[[[CustomTextFieldCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:textFieldIdentifier1]autorelease];
}
tfCell2.cellTextField.delegate=self; //set the delegate to self to implement textField delegate methods in self
tfCell2.userInteractionEnabled=YES;
The delegate is called, but keyboard does not show up.
We have tried following options mentioned in SO, but no luck yet
SO Link 1
SO Link 2
SO Link 3
All suggestions are welcome.. Many Thanks in advance.
Until you tap on cell, your table cell will be the event responder. To make keyboard appear over text field, you need to make your text field to consume event respond as :
In tableView:didSelectRow:atIndex method :
[self.cellTextField becomeFirstResponder]

UItableview and Keyboard with previous and next button scrolling issue - iPhone

Here I have a tableView on a scrollView. Each row contains a textField. Next button is ok(view animating properly on upword) but when I press on previous button on keyboard, I have to show down the view one by one according to the textField. How can I solve this? I have to do it in many views. Please help me as soon as possible. I badly need it. May be I'm doing wrong somewhere. Sorry for my language problem. Sample code may be helpful.
Hi Please try the below method to scroll your tableview up and down based on which text field is selected, write this code in textfield delegate method
- (void)textFieldDidEndEditing:(UITextField *)textField{
// calculate the nsindexpath based on the textfield which is selected
//- (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated;
[yourtableview scrollToRowAtIndexPath:calcutaedIndexPath atScrollPosition:UIScrollViewPositionTop animated:YES];
}
Hope it will help you

How To Stop keyBoard Appearence at click event on UITextview?

In my IPad Application i am using TextView only for Text Displaying.As i need to display a Larger Text Thats Why i am using UITextview due to its Scrolling Property instead of using UILabel.
In my application i do not need to edit Text in UITextview ,but problem for me is that when i click on Textview for scrolling the keyboard appear its hide my textview so i want that my keyboard is never appear on click event.i make a search but not find any Suitable solution.Any help will be appriated.Thanx
NEW ANSWER (previous one was not working properly)
OK so since that is not working because it disables scrolling also, you should try to:
Implement UITextFieldDelegate protocol
In your view controller add the text
#interface YourViewController () <UITextViewDelegate>
In viewDidLoad set yourself as a delegate:
yourUITextView.delegate = self;
Implement the delegate method below:
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
return NO;
}
When the textview is about to edit the text, this method will be called automatically. It returns no, so the editing won't start.
It is very important that you undo the changes from the previous answers: Do not set the editable field to NO
I tried it and it's working. Hope it helps!
OLD ANSWER
when you declare the variable, or in your viewdidload method, set the editable property to NO:
yourUITextView.editable = NO;
or
[yourUITextView setEditable:NO]
That should prevent the keyboard from appearing.
Go to .XIB file and you can uncheck behavior editable or programmatically
textView.editable = NO;

Resources