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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:51:24+00:00 2026-05-26T17:51:24+00:00

I’m trying to add a custom delegate to a custom UITableViewCell of mine. On

  • 0

I’m trying to add a custom delegate to a custom UITableViewCell of mine.

On this cell I have a button which need to fire a method in the ViewController where the UITableView is located on.

I’m doing all the usual steps to add a custom delegate but for some reason when I open the VC on runtime the app crashes and gives me a bad access error.

When I comment all the delegate code it works properly so my guess is that something is wrong the way I add my delegate. When I leave my id property uncommented it seems to crash.

I implement the protocol in the VC. I did assign the delegate to the cell in the cellForRowAtIndexPath:. All the delegate methods are in place.
I’ve been using similar constructions in other classes but never in a subclass of UITableViewCells before.

Before I post some code I would like to know if someone encountered this bug before. If and how he solved it or if it is even possible to make a custom delegate for an UITableViewCell subclass.


EDIT:

My customCell.h

#import <UIKit/UIKit.h>

@class MyTableViewCell;

@protocol MyTableCellProtocoll <NSObject>

-(void) didPressButton:(MyTableViewCell *)theCell;

@end

@interface MyTableViewCell : UITableViewCell
{

    UIButton *myButton;

    id<MyTableCellProtocoll> delegationListener;

}

@property (nonatomic,retain) UIButton *myButton;

@property (nonatomic,assign) id<MyTableCellProtocoll> delegationListener;

- (void) buttonAction;

@end

.m

#import "MyTableViewCell.h"

@implementation MyTableViewCell

@synthesize myButton;
@synthesize delegationListener;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code

        self.myButton = [UIButton buttonWithType:UIButtonTypeCustom];
        self.myButton.backgroundColor = [UIColor clearColor];
        self.myButton.frame = CGRectMake(5, 0, 10, 32);
        self.myButton.titleLabel.adjustsFontSizeToFitWidth = YES;
        [self.myButton addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:self.myButton];  
    }
    return self;
}

- (void) buttonAction
{
    NSLog(@"buttonpressed");
    [self.delegationListener didPressButton:self];
}

@end

MyVC implements the delegate as proper in the .h

@interface MyVC : UIViewController <UITableViewDelegate, UITableViewDataSource, MyTableCellProtocoll>

and it also uses the one delegatemethod from MyTableCellProtocoll in the .m

- (void)didPressButton:(MyTableViewCell *)theCell
{
    NSLog(@"didPressButton");
}

I assign the delegate in the cellForRowAtIndexPath:

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

    MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[MyTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        cell.delegationListener = self;
    }

    return cell;
}

These are all locations I use for the delegate.
What I want it to do is change the buttontitle and insert some rows after that cell (modified duplicates)

Hope this will clear things up a bit more.


EDIT2:
The button method is not being called at start as was metioned in the comment section. Editted code with logcode.


EDIT3:
There is nothing wrong with the button. It is the delegate property that is messed up somewhere. With breakpoints and logs and commenting i made sure of that.

The code is being run up to the last element in my datasource list then it crashes. 1 step closer to the problem now i suppose.


FINAL EDIT:
Ok, it seems like all of the delegates and buttons and other components weren’t the problem at all. It was the heightForRowAtIndexPath: screwing me over.
Thanks for all of your support anyhow!

  • 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-26T17:51:25+00:00Added an answer on May 26, 2026 at 5:51 pm

    This question has been solved.
    The problem wasn’t in the delegate and unrelated to the button issues in the other answers. The problem was lying in the access of a cell in the heightForRowAtIndexpath: and was easily solved once figured out.

    I was kindly pointed to the right direction by jrturton and for this he has my thanks.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
I have thousands of HTML files to process using Groovy/Java and I need to
I am trying to loop through a bunch of documents I have to put
I have some data like this: 1 2 3 4 5 9 2 6

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.