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 6139891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:02:53+00:00 2026-05-23T18:02:53+00:00

I have a UITextField that I am adding to a UITableViewCell to use as

  • 0

I have a UITextField that I am adding to a UITableViewCell to use as a search field for a long list of accounts. I have added it as follows:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    }

    if ((indexPath.section < accountsection) && (hasSearch) && (indexPath.row == 0)) 
    {
        // Search
        if (!searchField) 
        {
            searchField = [[UITextField alloc] initWithFrame:CGRectMake(20, 10, cell.frame.size.width - 40, 25)];
            [searchField setEnabled:YES];
            searchField.placeholder = NSLocalizedString(@"Search", @"search");
            searchField.keyboardType = UIKeyboardTypeDefault;
            searchField.returnKeyType = UIReturnKeySearch;
            searchField.autocorrectionType = UITextAutocorrectionTypeNo;
            searchField.clearButtonMode = UITextFieldViewModeAlways;
            searchField.delegate = self;
            [cell addSubview:searchField];
            [searchField release];
        }

        // Clean up an account label if needed
        cell.accessoryType = UITableViewCellAccessoryNone;
        cell.textLabel.text = @"";
        cell.detailTextLabel.text = @"";

        // Show the search field if it was hidden by a text label
        searchField.hidden = NO;
        [cell bringSubviewToFront:searchField];
    } 
}

To detect edits to the text field, I have set up the UITextFieldDelegate in the header and trap the following delegate calls:

@interface AccountViewController : UITableViewController <UITextFieldDelegate> {
    BOOL hasSearch;    
    UITextField *searchField;
...
}

In the implementation, I then handle these delegate methods:

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    NSLog(@"Done editing");
    [self filterAccountsBy:textField.text];
    [textField resignFirstResponder];
    return NO;
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    NSLog(@"Searching for %@", string);
    [self filterAccountsBy:string];    
    return YES;
}

However in the second one, unless I return YES, the text never changes; in the first one, returning YES seems to not affect me. But when I return YES in either, I get a nasty EXC_BAD_ACCESS.

I must be missing something in my manual adding of this UITextField to my cell but I can’t figure out what it is… can anyone assist?

Many thanks.


EDIT: As suggested below, I commented out the filterAccounts call and my app now no longer crashes. Here is the full code for this method:

- (void)filterAccountsBy:(NSString *)filterstring 
{
    [accounts removeAllObjects];
    if (([filterstring length] == 0) && (!isChooser) && (![vpmsConn isDomainLogon])) {
        [accounts addObject:[[vpmsConn accounts] objectAtIndex:0]];
    } 

    if ([filterstring length] == 0) {
        [accounts addObjectsFromArray:[cache accounts]];
    } else {
        for (AccountItem *ac in [cache accounts]) 
        {           
            BOOL found = NO;

            // Name search
            if ([[ac.clientName uppercaseString] rangeOfString:[filterstring uppercaseString]].location != NSNotFound) {
                found = YES;
            }

            //more similar searches

            if (found) {
                [accounts addObject:ac];
            }
        }   
    }

    [self.tableView reloadData];
}

I am a bit confused, though. When I filter this list using the textFieldShouldReturn and then return NO, it filters properly and does not crash. Something about returning YES from either one of these methods causes the crash after I have filtered. If I have not filtered at all, returning YES is no problem.

Let me know if there is any other code that I should post.

  • 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-05-23T18:02:54+00:00Added an answer on May 23, 2026 at 6:02 pm

    I have resolved the issue but I cannot (due to NDA) post the answer here yet. Those interested, and in the paid iOS developer program, should go to the NDA developer forums and search for UITextField EXC_BAD_ACCESS and you will find the answer…

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

Sidebar

Related Questions

I have a UITextField added to an UIAlerView (Kind of adding user to list
I've set up a UITableView with several custom UITableViewCell's that have some UITextField's and
I have a UITextField that I put into a UITableViewCell that I put into
I have a UITextField that has been added to my view in Interface Builder.
I have a UITextField that I want to display a pre-defined list of email
I have a UITextField that is a subview of a UITableViewCell . When my
I have a UITextField that responds to touch events when it is added as
I have a UITextField that I would like to enable auto completion on by:
I have a UITextField in my app that accepts decimal amounts for prices (i.e.,
I have an UITextField and I would like that for every tap on a

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.