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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:28:29+00:00 2026-05-18T20:28:29+00:00

Apologies if there answer is already out there, but I could not find it.

  • 0

Apologies if there answer is already out there, but I could not find it.

I have the following set-up: MainViewController which has a big UITableView and CustomTableViewCell which is subclass of UITableViewCell. Each instance of CustomTableViewCell has a UIButton added to its content view (all done programmatically).

When the button is pressed in a given cell, I would like for it to call the buttonPressed: method in MainViewController and, even better, tell me the indexPath.section for the cell containing the pressed button.

CustomTableViewCell has no nib file, all done programmatically. In CustomTableViewCell.h I declare:

    UIButton *mybutton;

Though I do not retain (no @property, @synthesize) it. The init method for CustomTableViewCell.m reads like this:

    myButton = [[UIButton alloc] init];
    [myButton addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventValueChanged];
    [[self contentView] addSubview:myButton];
    [myButton release];

but I want to call instead the “buttonPressed:” method that lives in the parent view. Been hacking away at this for a few hours, so I’d be grateful if someone could spare me my own stupidity. Thanks!

  • 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-18T20:28:29+00:00Added an answer on May 18, 2026 at 8:28 pm

    Then you go with the delegate pattern !

    Define a protocol that your controller will respect and a delegate of type id on your cell. Don’t forget to assign that delegate for every cell you create with your controller.

    Protocol :

    @protocol MyProtocol
    -(void)customCell:(MyCustomCell*)cell buttonClicked:(id)button;
    @end
    

    Property in your cell interface :

    @interface MyCustomCell : UITableViewCell ...
    ...
       id<MyProtocol> _delegate;
    ...
       @property (nonatomic, assign) id<MyProtocol> delegate;
    ...
    @end
    

    Synthesize your property with :

    @synthesize delegate = _delegate;
    

    Implement the delagate in your controller :

    @interface MyCustomContoller : UIViewController<MyProtocol>
    

    Set the delegate when you create your cells (from your controller)

    cell.delegate = self
    

    Then from the method called in your cell when the button is clicked :

    -(void) buttonClicked:(id)sender {
    [self.delegate customCell:self buttonClicked:sender];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Apologies if there answer is already out there, but I could not find it.
Apologies if this has been asked already, I can't find the answer in the
Apologies if this has been answered elsewhere, but I have yet to find a
Apologies if this is a repost, I could not find the search terms to
Apologies for this seemingly minor question, but I can't seem to find the answer
Apologies if this has been asked already. I've seen answers regarding static SQLs, but
apologize if there is already answer for that, but as a newbie to I'm
First off, let me apologize if this has been asked already, but I can’t
Please excuse me if there are already answers to this, but I can't quite
I've been googling this all day with out finding the answer, so apologies in

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.