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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:03:58+00:00 2026-05-17T17:03:58+00:00

My program is crashing because my TextField is sending messages to its delegate after

  • 0

My program is crashing because my TextField is sending messages to its delegate after the delegate has been deallocated. I have an object that serves as a UITableViewDataSource and a UITextFieldDelegate. In cellForRowAtIndexPath, I create a TextField inside each TableViewCell and assign self as the TextField’s delegate. When I click a button on the screen, the view reloads (it runs all the same code that is run when the view was loaded the first time):

DetailsViewController *controller = [[DetailsViewController alloc] initWithNibName:@"ClientView" bundle:nil];
self.detailsViewController = controller;
[controller release];

NRFCAppDelegate *appDelegate = UIApplication.sharedApplication.delegate;
for (UIView *view in [[[appDelegate.splitViewController.viewControllers objectAtIndex:1] view] subviews])
{
    [view removeFromSuperview];
}
CGRect rect = [[[appDelegate.splitViewController.viewControllers objectAtIndex:1] view] frame];
self.detailsViewController.view.frame = CGRectMake(0, 0, rect.size.width, rect.size.height);
[[[appDelegate.splitViewController.viewControllers objectAtIndex:1] view] addSubview:self.detailsViewController.view];

self.detailsViewController.detailsTitle.title = self.currentClient.name;
self.menuViewController.clientLabel.text = self.currentClient.name;

self.menuViewController.propertyLabel.text = @"Properties:";
self.menuViewController.addPropertyButton.hidden = NO;
self.menuViewController.editPropertiesButton.hidden = NO;

ClientMenuDelegate *menuDelegate = [[ClientMenuDelegate alloc] initWithRootController:self];
menuDelegate.properties = self.currentClient.properties.allObjects;
self.menuViewController.tableView.delegate = self.menuViewController.tableView.dataSource = menuDelegate;
self.menuViewController.delegate = menuDelegate;
[menuDelegate release];

ClientDetailsDelegate *detailsDelegate = [[ClientDetailsDelegate alloc] initWithRootController:self];
detailsDelegate.client = self.currentClient;
self.detailsViewController.tableView.delegate = self.detailsViewController.tableView.dataSource = detailsDelegate;
self.detailsViewController.detailsDelegate = detailsDelegate;
[detailsDelegate release];  

[self.menuViewController.tableView reloadData];
[self.detailsViewController.tableView reloadData];

self.detailsViewController.detailsDelegate = detailsDelegate; causes the previous ClientDetailsDelegate to be released (and therefore dealloced), because it is a retain-type property. The problem is that if my TextField was the FirstResponder when the reload button is clicked, it still sends it’s textFieldShouldEndEditing, textFieldEditorDidChangeSelection, etc, messages to the now dealloced ClientDetailsDelegate. It seems like those messages should get sent before any of the above code is executed, because the TextField is losing focus the moment the button is clicked. Also, once the removeFromSuperview is called, the TextField itself shouldn’t exist anymore anyway.

How can I make sure that the TextField is destroyed when I reload the view, and prevent it from sending messages to its delegate after the delegate has been dealloced?

  • 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-17T17:03:59+00:00Added an answer on May 17, 2026 at 5:03 pm

    The text field only sends those messages after all this stuff has happened possibly because the current control might refuse to accept first responder. Anyway, the reason is not important. The point is you are destroying a delegate before a control that uses it has finished with it. Before the line:

    self.detailsViewController.detailsDelegate = detailsDelegate;
    

    you need to set the delegate property of the control that the old delegate was for to nil. You could probably do it in the dealloc method of the delegate object.


    On another note:

    ClientMenuDelegate *menuDelegate = [[ClientMenuDelegate alloc] initWithRootController:self];
    menuDelegate.properties = self.currentClient.properties.allObjects;
    self.menuViewController.tableView.delegate = self.menuViewController.tableView.dataSource = menuDelegate;
    self.menuViewController.delegate = menuDelegate;
    [menuDelegate release];
    

    looks wrong. None of the properties you assign menuDelegate to are retain properties. I think it will go away as soon as you release it leaving dangling pointers (unless menuViewController is your own class and you have made the delegate property retain).

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

Sidebar

Related Questions

I noticed that my program was crashing because it was running out of memory.
I'm having trouble with my program crashing. I get that Program.exe has stopped working
I have been playing around with D 2.0 a bit today mostly because of
My company has started having a number of customers call in because our program
I have a WPF program that runs fine on the development PC and on
My program is crashing as a result of the runtime sending isEqualToString: to a
Is there is easy command in MATLAB which prevents program from crashing when it
How can I prevent the following code crashing my program? ::MessageBox(NULL, Lbefore, NULL, MB_OK);
This program I use has it's own variables to set when you run it,
I have a problem with my code. It keeps on crashing when i have

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.