I've dealt with Keyboards with a UITextField but how can I use a Keyboard in the following way:
I have a UITableView
When the user selects a specific row, a keyboard pops up
I'd like to have a method that knows everytime a letter or something is pressed on the keyboard
Place text fields on the cells using the tableView:cellForRowAtIndexPath: method, and give the text field on each cell its own tag to identify it in the table view or text field delegate methods. Optionally, have a cell's text field become first responder when the cell is tapped in tableView:didSelectRowAtIndexPath: (outside of the text field's region).
To make it look like part of the cells, ensure your text fields don't have borders and match the cell background color.
You can hide a tiny (1x1) invisible/transparent text field in the corner somewhere (temporarily make it a subview in the table view cell or on top of the entire table view), make the text field first responder, and trap any character inputs by implementing the text should change delegate and inspecting the replacement text before it's entered.
const CGRect kbottomPickerViewFrame = {{0.0f, 480.0f},{320.0f, 298.0f}};
const CGRect ktopPickerViewFrame = {{0.0f, 480-298},{320.0,298.0f}};
-(void) animateViewUp:(BOOL)up {
[UIView animateWithDuration:.5 animations:^{
if(up) {
self.view.frame = ktopPickerViewFrame;
}else {
self.view.frame = kbottomPickerViewFrame;
}
} completion:nil];
}
use this method it will animate the view . Call it when textField begin editing
Related
I have a uiview with a button on that. When click on that button i am showing a subview.
The subview contains a table view and a search display controller. when i enter something on search bar it will be showing the search result tableview.
once search is done and going back to the superview and again come back to subview, the table view that displays all the records is not scrollable and also the search bar contains the text that has been entered before, that is search bar contains text but the tableview is not search result table view.
This issue will not come if i click on Cancel button of searchbar, without clicking on cancel button if i go back to superview, the issue arises.
When you show yourTableview with searchBar at that time set bellow code..
searching = NO; // if you use this BOOL value..
and also clear the text of UISearchBar's text i.e.
searchBar.text = #"";
and after reloadData of UITableView
-(void)showSearchTable // its an example
{
searching = NO;
searchBar.text = #"";
[yourTableView reloadData];
}
Is there any way to hide or do not show the keyboard without calling resignFirstResponder in iOS? I know different method to hide keyboard, first one is to make the textview non editable, or using
- (BOOL)textFieldShouldEndEditing:(UITextView *)textview
{
[textview resignFirstResponder];
}
but in my case these method will not be works out, becz I just want to dismiss or hide the keyboard only, but need the editing in textview. I have a textview which contains some text, when I tap the sentence it need to be selected, I have done that selection part nicely, but when I write above keyboard dismissal method in my project, the selection of the tapped sentence doesn't appear,.is there any method to o this.
Textfield's selection will remain only when you are in editing mode. When you resign your first responder your selection disappears too.
To avoid bringing keypad in editing mode, you can change the input view. For example , look at the code,
textview.inputView = [[UIView alloc] init];
This brings a custom input view and it is not visible.
Add
self.textView.editable = NO;
Try this
NSRange selection = [yourTextView.text rangeOfString:yourTextView.text];
if( selection.location != NSNotFound ){ yourTextView.selectedRange = selection; }
It will remove the keyboard from the textview. Hope it helps.
I am using a UITextView to display the text from a xml.I parsed the xml and stored the text in a NSArray and from there i am adding it to a UITextview in my code.
problem:
When i run the code the textview shows as empty or with partial text,and when i try to scroll the textview the whole text is getting displayed.
I added the UITextview to a UIView.
i found it strange and googled it but could not find many answers which helps me.
Can someone reply me to solve the issue
TNQ
Found a simple SOLUTION
Had the same problem. When you put text into a UITextView which is not visible, it doesn't draw the text.
I had my UITextView off screen and animated it in like this:
[UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationCurveEaseOut animations:^{
self.contentView.center = CGPointMake(self.contentView.center.x + move * (self.contentView.frame.size.width /2), self.contentView.center.y);
self.textView.frame = self.textView.frame; // <<<--- ADD THIS LINE
} completion:^(BOOL finished) {
if (finished) {
}
}];
When you re-set the textview's frame, it re-draws it's text. So all you need to do is add the line I marked above before your UITextView comes on screen.
Cheers
UITextView inherits from UIScrollView, so just scroll it.
[detailsTextView setContentOffset:CGPointMake(0, 1) animated:YES];
i solved the issue by clearing the textview and added the text to the textview again,i dont know the exact funda but my issue is solved.
in my case:
i am changing the frame of the textview from outside to the view on click of a button.while the button is clicked the textview is not showing content and on scroll it shows.
i solved, by deleting the text from textview and re entering the text on clicking the button.
UItextView inherits from UIScrollView. That means it has scrolling functionality. Thus, if the contents of the UITextView is small enough to fit in its frame, it doesn't need to scroll.
But, if it is large enough, you need to scroll the UITextView.
Does this makes sense?
For more information, refer the class reference of UITextView
Ensure that, method in which u set textview's text is call properly.And string which u assign to text view is in proper string format(if not so retain it).
There are chances that the whitespaces and/or newlines are there before the actual text. Trim those characters before you assign it to text view.
NSCharacterSet *charset = [NSCharacterSet whitespaceAndNewlineCharacterSet];
NSString *text = [parsedString stringByTrimmingCharactersInSet:charset];
textview.text = text;
Please try it when your textView is loading
NSAttributedString *oldtext = objTextView.attributedText;
[objTextView removeFromSuperview];
objTextView.attributedText = oldtext;
[self.view addSubview:objTextView];
In my case my text is attributed
When you complete the operation which parses the XML are you ensuring that your update is occuring on the main thread ?
UIKit only updates on the main thread so any updates made off it will only show up next time you touch the object and force an update.
As an example of one way to do it correctly.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
[self parseXMLOffMainThread];
dispatch_async(dispatch_get_main_queue(), ^{
self.myTextView.text = parsedText;
});
});
I want to have a text-send view like the send-email view from the email app by apple. (the default iPhone emailapp).
I tried a UIScrollView with 2 TextFields and 1 TextView, but it looks not good, the scrollview has no function and the view does not scroll when I enter a text in the TextView (the text is hiding in the third line when I type...
Here is a picture:
http://s3.imgimg.de/uploads/Bildschirmfoto20110823um1156940f792556940f791456940f79png.png
It should look like this:
http://a5.mzstatic.com/us/r1000/032/Purple/ea/4f/03/mzl.bxracfen.320x480-75.jpg
How to rebuild?
to scroll downside when you start writing the text inside UITextfield, use this :
[yourScrollView scrollRectToVisible:CGRectMake(yourTextfield.frame.origin.x,yourTextField.frame.origin.y,yourScrollView.frame.size.width,yourScrollView.frame.size.height) animated:YES];
Also, when you edit your TextView (i.e in the textViewDidBeginEditing method), make its frame smaller so as to make it fully visible. Then, when you finish editing the text (i.e in the textViewDidEndEditing method) set the frame to whatever it was, originally.
EDIT:
//add this in .h file
NSInteger originalHeight;
//in .m file
- (void) textViewDidBeginEditing:(UITextView *)textView
{
[yourScrollView scrollRectToVisible:CGRectMake(yourTextView.frame.origin.x,yourTextView.frame.origin.y,yourScrollView.frame.size.width,yourScrollView.frame.size.height) animated:YES];
//now set the frame
//you just need to change the height, rest can be kept whatever they are
//set the newHeight so as to make the textview visible
originalHeight = yourTextView.frame.size.height;
yourTextView.frame = CGRectMake(x,y,width,newHeight);
//rest of the code
}
Now when editing is completed, set the height to as it was before.
- (void) textViewDidEndEditing:(UITextView *)textView
{
yourTextView.frame = CGRectMake(x,y,width,originalHeight);
}
I use Textview for insert message text but when i focus in textview second time after insert some text then already inserted text shifted upside. so text cut in the TextView.
Any solution for this problem?
UITextView the subclass of UIScrollView. So you can discard scroll to top like this:
((UIScrollView*)someTextView).delegate = self; // or some other UIScrollViewDelegate
and implement this method:
-(void) scrollViewDidScroll:(UIScrollView*) scrollView {
scrollView.contentOffset = CGPointMake(0, 0);
}
But if you do need scrolling during edit, you can add some boolean flags to distinguish the situations when user is scrolling and when the scrolling is automatic.