Is there any way to check the size of a message that is executed in your code? And how to get to it?
I have 3 textFields and delegated them, and used protocol
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[self.toTextField resignFirstResponder];
[self.subjectTextField resignFirstResponder];
[self.bodyTextField resignFirstResponder];
return YES;
}
I want to see the size (RAM) that is taken up, by me clicking the return key on one of the keyboards.
You need to use Instruments to check the memory usage.
Check out this question.
Related
When I updated my xcode and ios 11.0 ...Some UI changed. I mean there alignment and positions.
One serious issue is coming in my project is that, keyboard is not hiding.
Scenario is Suppose I am typing something in UITextfield and move to next UITextfield. Here in second UITextfield I used UIActionSheet pickerview. So, when i click on second UITextfield then UIActionSheet pickerview is coming as well as previous keyboard is not hiding. UIActionSheet picker is showing back of keyboard and keyboard is not hiding.
See the above Image.
I already posted this issue here,
UITextView issue with ActionSheetStringPicker Picker view
again same question..! I already given solution for this question. Check below link,
UITextView issue with ActionSheetStringPicker Picker view
Here my answer
#pragma mark - UITextField Delegate methods
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
if ([textField isEqual:txtFldActionSheetPicker]) {
[textField resignFirstResponder];
return NO;
}
else
return YES;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}
I'd like to achieve the following behaviour of a single UITextField and the keyboard:
when the view has loaded UITextField becomes first responder and the keyboard opens (so far so good):
- (void)viewDidLoad
{
[self.editField becomeFirstResponder];
self.editField.delegate = self;
}
Now user inputs some text and presses the return key. That text is added to the data source in the following method:
- (IBAction)didEndOnExit:(id)sender {
//add self.editField.text to data source
}
Now after the return key is pressed and the above UITextField's method gets called and executed I would like the UITextField to clear, the cursor to be placed and be visible at the beginning of the text field and the keyboard not to hide so that new item could be entered in the textfield and added to the data source.
This is how I return to the previous view in the app (using a button):
- (IBAction)backButtonPressed:(id)sender {
[self dismissViewControllerAnimated:NO completion:^{}];
}
I tried playing with UITextFieldDelegate's methods and UITextField's becomeFirstResponder and resign FirstResponder, but am unable to achieve the above described behaviour. I've seen posts here on Stack Overflow about using consecutive UITextField's to enter data, but not to use the same UITextField time and again.
You should override the below mentioned method and do whatever you want and showing the keyboard too.
- (BOOL)textFieldShouldReturn:(UITextField *)textField
Have a try :)
While dismissing view controller all other code executions freezes when (view controller is being dismissed).
Use some delay (performselectorafterdelay). or
completionhandler of dismissingviewcontroller for executing your code when viewcontroller is being dismissing and
Also execute code on main Thread which includes UI changes or updates
after saved your data.. you have to make the uitextfield to be nil... like self.editField.text = nil. then you can call [self.editfield becomesfirstresponder].. after you will add more items to array or else anything everytime the field should be nil after you added..
From the Doc
Return Value: YES if the text field should implement its default
behavior for the return button; otherwise, NO.
For EX - Use the Delegate of UITextField :
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
//add self.editField.text to data source
textField.text = #"";
return NO; // This will do your need
}
Because I used UITextField's action method - (IBAction)didEndOnExit:(id)sender the keyboard always got closed. Apparently that method makes the UITextField resign from being first responder. Instead of adding data to data source in that method, it can be added in the delegates's method - (BOOL)textFieldShouldReturn:(UITextField *)textField and so the keyboard won't close.
I know this is a basic question but i´m a little confused, so i hope you can help me. I have a tableview with multiple dynamic tableview cells, and inside each tableviewcell i have multiple textfields. Each cell has a different tag and also the textfields and i want to access the uitextfields values as you can imagine. My problem is, i´m not using IBoutlet for the textfields (it would be a enormous amount of IBoutlets)...I´m using - (void)textFieldDidEndEditing:(UITextField *)textField...but i just can´t seem to make the correct connections in the IB, this is my code:
-(void) textFieldDidEndEditing:(UITextField *)textField
{
if (textField == [self.view viewWithTag:102]) {
[textField resignFirstResponder];
}
After this, do i have to connect the respective UItexfield (and all textfields) to self? and then, do i have to use the editing did end event?...
Regards
I guess that the answer to this question is another question: What do you want to do with the text that the user enters?
I assume that you have some kind of data model that you want to store the data in.
If so, then when this function is called, you need to take the text that is already in the textField and save it to your data model immediately as it is entered.
For instance, you can access the text that was entered like this:
-(void) textFieldDidEndEditing:(UITextField *)textField
{
if (textField == [self.view viewWithTag:102])
{
[textField resignFirstResponder];
yourDataModel.stringToSave = textField.text;
}
}
I want to hide the keyboard when i press any key other than the return key .
For example when the user presses the character 'n' on keyboard , keyboard should disappear.
Please provide me a suitable answer as soon as possible.
Thanks in advance.
You may try UIKeyInput protocol. To catch a insert with insertText
http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIKeyInput_Protocol/Reference/Reference.html
Have you used protocols?
EDIT:
Then you can use method
[textField resignFirstResponder];
To hide the keyboard
EDIT2: Protocols
In short, the interface for class that you want to respond to the protocol must be declare as (in YourClass.h):
#interface YourClass:NSObject<UIKitInput>
then, you have to implements the protocol methods in YourClass.m:
#pragma mark -
#pragma mark UIKeyInput Protocol Methods
- (BOOL)hasText {
.....
return NO;
}
- (void)insertText:(NSString *)theText {
...;
}
- (void)deleteBackward {
....
}
Good Luck!
For that, you have to create a custom keyboard or you have to override the Keyboard methods. But you cannot override. Because You do not know, in which method and what code is to sense that key pressing in that frameworks. So better write a custom keyboard anyway.
The keyboard hides when the text field resigns first responder. The textfield delegate is told when a key is pressed (textField:shouldChangeCharactersInRange:replacementString:). If you need any more detail than that, please put a bit more effort into your question and show us what you have tried so far.
I have some text edit fields, and also a button to show a uidatepicker.. if I go to the uitextedit, the keyboard appears, but when I click the button, the keyboard is still here...
how can I remove it?
thanks!
You need to use resignFirstResponder, see this similar question.
[myTextField resignFirstResponder];
See this answer for the easiest way to do it: Easy way to dismiss keyboard?
[self.view endEditing:YES];
Call -resignFirstResponder on your currently-editing text field.
There are cases where I don't have direct access to the 'first responder', so I tend to use a different approach.
I have a utility class for the keyboard with, among other functions, this one:
+ (BOOL)dismiss:(UIView *)view
{
if (view.isFirstResponder) {
[view resignFirstResponder];
return YES;
}
for (UIView *subView in view.subviews) {
if ([Keyboard dismiss:subView]) // It's calling itself, just to be perfectly clear
return YES;
}
return NO;
}
This lets me simply call for example: [Keyboard dismiss:self.view] from anywhere within a UIViewController.