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

  • Home
  • SEARCH
  • 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 6724831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:44:09+00:00 2026-05-26T09:44:09+00:00

I have a UIButton that is added to each UITableViewCell (except for 2 cells)

  • 0

I have a UIButton that is added to each UITableViewCell (except for 2 cells) in a tableview.
The button’s target is the UITableViewController.
I noticed that the app has crashed when the action has been sent to the wrong target. I’m assuming that this is because the target has somehow been deallocated (even though, if the UITableViewController has been deallocated, the buttons should not be visible, and not pressable (and should be deallocated themselves)).

I’m guessing I need to balance the addTarget method, with the removeTarget. Like KVO and retain/release.

But I’m not sure where to do this, because I only have a reference to the button when it is being created and added to the cells, in cellForRowAtIndexPath:?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
        UIButton *extraButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        [extraButton setFrame:CGRectMake(0, 0, 60, 30)];
        [extraButton setTitle:@"Meta" forState:UIControlStateNormal];
        [extraButton addTarget:self action:@selector(extraButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
        cell.accessoryView = extraButton;
    }

    if (indexPath.row == kNoExtraButtonRow) {
        cell.accessoryView.hidden = YES;
    } else {
        cell.accessoryView.hidden = NO;
    }
    //set textlabels etc...
    return cell;
}
  • 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-26T09:44:10+00:00Added an answer on May 26, 2026 at 9:44 am

    If you have subclassed UIButton for this or have subclassed UITableViewCell then you can put the code in there to remove the target action for the button when the cell or button is deallocated. In the UITableViewCell’s dealloc you can call removeTarget on the its button, or in the button’s dealloc it could call removeTarget for itself.

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

Sidebar

Related Questions

I have an app that uses a tableview, along with a UIButton that I
I have a UITableViewCell that has 2 UIButton instances. Both buttons have a default
I have a UIButton that is created inside of each table cell. I want
I have a custom class, and that class has a UIButton instance variable. I
I have a UIButton that is added to a UIImageView (it's a big chart)
Ok i have a table view that can add and delete cells. For each
In my iPad app, I have a UIButton that is calling an IBAction to
I have a very simply subclass of UIButton that will fire off a custom
I have a method that accepts a sender and is called with a UIbutton.
I have a detail view that includes three UIButtons, each of which pushes 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.