Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8434071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:33:30+00:00 2026-06-10T06:33:30+00:00

HEADS UP EDIT: I posted the (simple) answer to this below. No need to

  • 0

HEADS UP EDIT: I posted the (simple) answer to this below. No need to waste time looking through all this code. Also see structural suggestions in Jack Lawrence’s answer.


I’ve set up a UITextField in a tableViewCell that starts out with enabled = NO. Later it is changed to enabled = YES so that it can become first responder and call a keyboard, etc.

But once enabled is NO, it can never be YES again:

tf.enabled = YES;
printf(" Is tf enabled? %d", [tf isEnabled]); // this prints 0 — it refuses to be re-enabled.

Even weirder, if I subclass UITextField and give it a simple custom method, I am able to call that method successfully from the controller — before enabled is set to NO. Once enabled is NO, calling the custom method does nothing. There are no warnings or exceptions; it just doesn’t run.

So the problem isn’t just some trouble with the responder chain. The once-disabled textfield behaves like a black hole.

I did take a look at Apple’s demo for editable textfields in cells, “TaggedLocations,” and they fiddle with enabled with complete impunity: nameField.enabled = NO; and nameField.enabled = YES; and everything goes like clockwork.

There is one other clue: The UIControl class ref says, “If the enabled state is NO, the control ignores touch events and subclasses may draw differently.” But refuse to be re-enabled? Refuse to accept method calls? I don’t get it.


OK, this is probably more than you really want to look at, but hopefully there are some clues buried in it.

Here are the UITextField subclass’s h and m files:

#import "FooNameFieldForCell.h"

@implementation FooNameFieldForCell

- (BOOL) canBecomeFirstResponder {
    printf("\nCBFR called, self.enabled is %d.", self.enabled); 
    if (self.enabled)
        return YES;
    else
        return NO;
}

- (BOOL) canYouHearMe:(id)sender {
    printf("Yes, I hear you."); 
    return YES;
}

@end

#import <UIKit/UIKit.h>

@interface FooNameFieldForCell : UITextField {

}

- (BOOL) canYouHearMe:(id)sender;

@end

Here’s the cellForRow and the action method:

BOOL bPortrait = UIInterfaceOrientationIsPortrait(self.interfaceOrientation);

// Cell Which Layout
NSString *identifier = nil;
UITableViewCell *cellFooList = nil;
switch (indexPath.row) {
    case 0:
        // this textfield is in row 0
        identifier = bPortrait ? @"cellFooListName_portrait" : @"cellFooListName_landscape";
        cellFooList = [tableView dequeueReusableCellWithIdentifier:identifier];
        if (!cellFooList)
            cellFooList = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier] autorelease];
        break;
    // other rows…
}

// Foo
Foo *Foo = [self.frcFoosAllReg_byName.fetchedObjects objectAtIndex:indexPath.section];

// Cell Fill
switch (indexPath.row) {
    case 0: {
        if (cellFooList.tag == 1) {
            for (UIView *subview in cellFooList.subviews) {
                if (subview.tag == 2) {
                    ((FooNameFieldForCell *)cellFooList).text = Foo.FooName;
                    break;
                }
            }
            break;// dequeued cell, already done 
        }

        // button "Edit"
        // (Yes, I know you’re supposed to put this on the navBar, but as a user I have never liked that metaphor. I’m doing the editability by section/row.) 
        UIButton *btnEditFooName = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        [btnEditFooName addTarget:self action:@selector(presentEditFooName:) forControlEvents:UIControlEventTouchUpInside]; // the selector is where I’m trying to enable the textfield
        // do button setup & framing
        [btnEditFooName setFrame:rectBtnEditFooName];
        [cellFooList.contentView addSubview:btnEditFooName];

        // TEXTFIELD SETUP FOLLOWS   

        // do framing
        FooNameFieldForCell *tfFooName = [[FooNameFieldForCell alloc] initWithFrame:rectFooName]; 
        [tfFooName canYouHearMe:self]; // custom method runs OK here
        tfFooName.text = Foo.FooName;
        tfFooName.enabled = NO;
        tfFooName.tag = 2; // tag to locate among cell's subviews
        [cellFooList.contentView addSubview:tfFooName];
        [tfFooName release];
        // no row selection allowed
        cellFooList.selectionStyle = UITableViewCellSelectionStyleNone;
        // tag as done
        cellFooList.tag = 1;
        break;
    // other cases…
    }
}
return cellFooList;
}

// Called by the Edit button:
- (void) presentEditFooName:(id)sender {

    // Determine which Foo is associated with sender.
    if (![sender isKindOfClass:[UIButton class]])
        return;
    UIView *cell = ((UIButton *)sender).superview.superview;
    if (!cell || ![cell isKindOfClass:[UITableViewCell class]])
        return;
    NSIndexPath *indexPath = [self.tvFooList indexPathForCell:((UITableViewCell *)cell)];
    Foo *Foo = [self.frcFoosAllReg_byName.fetchedObjects objectAtIndex:indexPath.section];

    FooNameFieldForCell *tfFooName = nil;
    for (UIView *subview in cell.subviews) {
        if (subview.tag == 2) {
            tfFooName = subview;
            break;
        }
    }

    // BLACK HOLE
        // because tfFooName is nil. But why? It shows up in the cell.

    tfFooName.enabled = YES; 
    [tfFooName becomeFirstResponder];
    printf("\ntfFooName can become firstResp? %d", tfFooName.canBecomeFirstResponder); // always prints 0, can't be firstResp
    [tfFooName canYouHearMe:self]; // does not run
    printf(" Is tfFooName enabled? %d", [tfFooName isEnabled]); // prints 0, still disabled

}

Well, my mysterious black hole turns out to be — null! OK, seems obvious now, especially since objective-c allows calls on null. But I’m left with another mystery: The field’s text appears in the cell, so how can it be nil?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T06:33:31+00:00Added an answer on June 10, 2026 at 6:33 am

    As is usual when I’m tearing my hair out, the black hole mystery turned out to be simple.

    This…

    FooNameFieldForCell *tfFooName = nil;
    for (UIView *subview in cell.subviews) {
        if (subview.tag == 2) {
            tfFooName = subview;
            break;
        }
    }
    

    …should have been this:

    FooNameFieldForCell *tfFooName = nil;
    for (UIView *subview in ((UITableViewCell *)cell).contentView.subviews) {
        if (subview.tag == 2) {
            tfFooName = subview;
            break;
        }
    }
    

    Custom views are one layer down, in the cell’s contentView, not its direct subviews. Aargh! So much time wasted!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT 2009-Nov-04 OK, so it's been a little while since I first posted this
We've been bashing our heads off of this one all morning. We've got some
I'm having a really hard time with this one, EDIT: I'm putting this edit
I need a straightforward, easy to understand answer on this one. I'm building a
All I need to do is a simple read from a file in the
Heads starting to hurt. I think I dropped into this too fast... Perhaps someone
I am banging my heads against the desk here friends. This is what I'm
Been banging our heads on this for two weeks now. Any help will be
I understand the concepts behind refs/heads/ , refs/remotes/ , and refs/tags/ . From time
EDIT: This works now thanks to ' olly_uk ' EDIT2: It works now, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.