textview如何像textfield一样工作?

时间:2011-09-19 09:53:56

标签: iphone

我正在开发一个应用程序,在该应用程序中我使用TextView输入数据。

如何退出TextView并重新签名键盘?

2 个答案:

答案 0 :(得分:2)

使用此委托方法和返回键扣除来重新签名textview.see here

确保你有

   urTextView.delegate=self;

和你的viewcontroller.h文件

  @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;
}

答案 1 :(得分:2)

要重新签名文本视图的键盘,您必须处理UITextview的委托方法。

以下是重新签名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;
}