1

我有两个 UITextViews!我遇到的问题是,我希望在输入一个 textView 而不是另一个时执行一个操作!我将操作代码放入

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView

但是当输入任一文本视图时,就会执行该操作。是否有一种方法可以通知何时使用某个文本视图?

4

3 回答 3

1

你可以设置tag你的UITextView来区分它们。

// Somewhere in your code
UITextView *firstTextView = // set up your text view
firstTextView.tag = 0;

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView {
    // ...
    if (textView.tag == 0) {
        // firstTextView
    }
    // ...
}
于 2013-06-12T12:33:47.203 回答
1

为此目的,它本身 textView 作为参数传递给委托函数

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView

您可以维护 textview 实例的属性,并在委托调用中检查哪个 textview 接收到了触摸。

于 2013-06-12T12:36:50.927 回答
1

你可以通过两种方式做到这一点

第一的

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
    if ( textView == YourTextView ) 
    {
            // ----- do here 
    }
    return YES;
}

其次是

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
    if ( yourTextView.tag == yourTag) 
    {
            // ----- do here 
    }
    return YES;
}
于 2013-06-12T12:38:12.093 回答