How to enable/disable a UITextField or UITextView programmatically?

  • I have a UITableView that's part of a Navigation-based Application.
    There's one .xib, a DrinkDetailViewController class (.m & .h files)
    and an AddDrinkViewController class which inherits from
    DrinkDetailViewController. Both share the same view, which contains a
    UITextField, two UITextViews, and some UILabels. The
    DrinkDetailViewController.h declares three IBOutlets as follows:

    #import <UIKit/UIKit.h>

    @interface DrinkDetailViewController : UIViewController
    {
    IBOutlet UITextField *nameField;
    IBOutlet UITextView *ingredientsView;
    IBOutlet UITextView *directionsView;
    ...
    }

    @end

    so that I can access the UITextField, and the two UITextViews. IB
    shows in the inspector window, that the UITextField, and UITextViews
    have a BOOL enabled property (controlled by a checkbox labeled
    "Enabled"). But the following doesn't work:

    ...
    nameField.enabled = YES;
    ingredientsView.enabled = YES;
    directionsView.enabled = YES;
    ...

    in the viewDidLoad: method of AddDrinkViewController. I unchecked the
    enabled box for these controls as the normal use of the view is just
    to display drink information, not for data entry. The
    AddDrinkViewController re-uses the view for data entry, and I want to
    re-enable the fields, but only when the view (xib) is used/loaded by
    the AddDrinkViewController. I looked in the docs for UITextField, but
    didn't even see a reference to an enabled property. Is this another
    of those view-within-a-view problems?
  • On Jan 13, 2010, at 6:22 PM, William Squires wrote:

    > I have a UITableView that's part of a Navigation-based Application. There's one .xib, a DrinkDetailViewController class (.m & .h files) and an AddDrinkViewController class which inherits from DrinkDetailViewController. Both share the same view, which contains a UITextField, two UITextViews, and some UILabels. The DrinkDetailViewController.h declares three IBOutlets as follows:
    >
    > #import <UIKit/UIKit.h>
    >
    > @interface DrinkDetailViewController : UIViewController
    > {
    > IBOutlet UITextField *nameField;
    > IBOutlet UITextView *ingredientsView;
    > IBOutlet UITextView *directionsView;
    > ...
    > }
    >
    > @end
    >
    > so that I can access the UITextField, and the two UITextViews. IB shows in the inspector window, that the UITextField, and UITextViews have a BOOL enabled property (controlled by a checkbox labeled "Enabled"). But the following doesn't work:
    >
    > ...
    > nameField.enabled = YES;
    > ingredientsView.enabled = YES;
    > directionsView.enabled = YES;
    > ...
    >
    > in the viewDidLoad: method of AddDrinkViewController. I unchecked the enabled box for these controls as the normal use of the view is just to display drink information, not for data entry. The AddDrinkViewController re-uses the view for data entry, and I want to re-enable the fields, but only when the view (xib) is used/loaded by the AddDrinkViewController. I looked in the docs for UITextField, but didn't even see a reference to an enabled property. Is this another of those view-within-a-view problems?

    The    enabled    property is defined in UIControl --- the super-class of UITextField . . .

    This is a good time for a plug for Xcode's incredibly useful but oft skipped over Class Browser,
    the second item in Xcode's  Project  menu . . .

        Cheers,
            . . . . . . . .    Henry

    =================================================
    iPhone App Development and Developer Education . . .
            Visit  www.nonatomic-retain.com

    Mac OSX Application Development, Plus a Great Deal More . . .
            Visit  www.trilithon.com
previous month january 2010 next month
MTWTFSS
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Go to today