user2366782
user2366782

Reputation:

Is there a way to know when a certain UITextView has been entered?

I have two UITextViews! The problem i have is that I want an action to be performed when one of the textViews is entered and not the other! I placed the action code in

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView

But the action is performed when either text view is entered. Is there a method that informs when a certain text view is being used?

Upvotes: 1

Views: 144

Answers (3)

Dharmbir Singh
Dharmbir Singh

Reputation: 17535

You can do it in two ways

first

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

Second is

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
    if ( yourTextView.tag == yourTag) 
    {
            // ----- do here 
    }
    return YES;
}

Upvotes: 1

Adithya
Adithya

Reputation: 4705

Its for this purpose itself textView is passed as an argument to the delegate function

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView

You can maintain properties for the textview instances and within the delegate call just check which of the textview received the touch.

Upvotes: 1

tilo
tilo

Reputation: 14169

You can set the tag of your UITextView to differentiate them.

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

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView {
    // ...
    if (textView.tag == 0) {
        // firstTextView
    }
    // ...
}

Upvotes: 1

Related Questions