when textview empty, detecting it and disabling Button
In response to Victor Alexander on May 22, 2010 7:29 PM

This is what the 'delegate' property of the UITextField (or UITextView) is for. Then implement the appropriate delegate method so you get notified each time the field is changed. Then call your 'disabled' method from there.

In response to RickMaddy on May 22, 2010 11:47 PM

@RickMaddy thanks! So I'm really close... I know I'm missing something but I'm not quite sure what it is.

in my .h file I added my delegate to the view controller


UIViewController <UITextViewDelegate> 

I also added the following instance method that should tell the delegate that the text or attributes in the specified text view changed.


-(void)textViewDidChange:(UITextView *) textView1; 

In my .m file

I added a condition to the method above:


- (void) textViewDidChange:(UITextView *)textView1{      if (textView.text.length == 0) {           //disable button           moreButton.enabled = false;      }      else {           //enable button           moreButton.enabled = true;      } } 

I know that I'm missing something related to my delegate, but I'm not quite sure how to work this... even though I've read the documentation :/ Sorry to keep asking!


@property(nonatomic, assign) id<UITextViewDelegate> delegate 
In response to Victor Alexander on May 23, 2010 6:16 AM

"I'm not quite sure how to work this."

Two observations:

One, you have a typo.

You use textView1 as the parameter, and in the body of the method you use textView.

Two, connect the UITextView's delegate to you custom view controller class.

Try this:

  1. Open the view containing the UITextView.
  2. Double click on the View icon in the document window  to make sure the view is open in its editor window.
  3. Select the UITextView.
  4. Open the inspector to the Connections pane (cmd-2).

  5. Make a connection from the delegate to the File's Owner. Just click the delegate outlet and drag to the File's Owner icon the in the document window. Afte dragging you should see something like this:

  6. Save the nib file.
In response to Jeremy French on May 23, 2010 8:20 AM

Or if you are not using IB then in your view controller's 'viewDidLoad' method add the line 'textView.delegate = self'.







https://devforums.apple.com/message/223850

Posted by 오늘마감