开发者

How textview work like as textfield?

I am developing one app, in that app I use TextView to enter the data.

How to开发者_运维知识库 quit the TextView and resign the keyboard?


use this delegate method with return key deduction to resign textview.see here

make sure u have

   urTextView.delegate=self;

and in ur viewcontroller.h file

  @interface urViewController : UIViewController<UITextViewDelegate> {


- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range 
 replacementText:(NSString *)text
{
        // Any new character added is passed in as the "text" parameter
    if ([text isEqualToString:@"\n"]) {
            // Be sure to test for equality using the "isEqualToString" message
        [textView resignFirstResponder];

            // Return FALSE so that the final '\n' character doesn't get added
        return NO;
    }
        // For any other character return TRUE so that the text gets added to the view
    return YES;
}


For resign the keyboard of text-view you have to handle the delegate method of UITextview.

Below is the code for resign the keyboard of UITextview.

- (BOOL)textViewShouldEndEditing:(UITextView *)textView
{
    [textView resignFirstResponder];
    return YES;
}

-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    if([text isEqualToString:@"\n"])
    {

    }
    return YES;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜