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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:39:57+00:00 2026-06-14T13:39:57+00:00

I am customizing a UITableViewCell with several subviews: – (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self

  • 0

I am customizing a UITableViewCell with several subviews:

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  if (self) {
    _mainView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 40.0f)];

    _hiddenOptionsView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 40.0f)];

    _menuView = [[CellMenuView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 20.0f)];

    [self addSubview:_menuView];
    [self addSubview:_hiddenOptionsView];
    [self addSubview:_mainView];
  }
  return self;
}

The class CellMenuView is a UIView subclass which has two UIButtons with their counterpart target actions setup on initialization:

- (id)initWithFrame:(CGRect)frame {   
  self = [super initWithFrame:frame];
  if (self) {
    UIImageView *background = [[UIImageView alloc] initWithFrame:frame];
    [background setImage:[UIImage imageNamed:@"cell_menu_bg.png"]];
    [self addSubview:background];

    CGFloat buttonX = frame.origin.x;
    CGFloat buttonY = frame.origin.y + 3.0f;
    CGFloat buttonWidth = frame.size.width / 2.0f;
    CGFloat buttonHeight = 10.0f;

    _editButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _editButton.frame = CGRectMake(buttonX, buttonY, buttonWidth, buttonHeight);
    _editButton.backgroundColor = [UIColor clearColor];
    _editButton.titleLabel.shadowColor = [UIColor blackColor];
    _editButton.titleLabel.shadowOffset = CGSizeMake(0.0f, -1.5f);
    _editButton.titleLabel.font = [UIFont boldSystemFontOfSize:22.0f];
    [_editButton setTitle:@"Edit" forState:UIControlStateNormal];
    [_editButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_editButton addTarget:self action:@selector(editButton:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_editButton];

    _fireButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _fireButton.frame = CGRectMake(buttonWidth, buttonY, buttonWidth, buttonHeight);
    _fireButton.backgroundColor = [UIColor clearColor];
    _fireButton.titleLabel.shadowColor = [UIColor blackColor];
    _fireButton.titleLabel.shadowOffset = CGSizeMake(0.0f, -1.5f);
    _fireButton.titleLabel.font = [UIFont boldSystemFontOfSize:22.0f];
    [_fireButton setTitle:@"Fire" forState:UIControlStateNormal];
    [_fireButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_fireButton addTarget:self action:@selector(fireButton:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_fireButton];

    return self;
  }
}

I have implemented the target action methods but they aren’t being executed. Instead, didSelectRowAtIndexPath: takes precedence over the touch up events inside buttons every time I pressed one of them.

The only way I have been able to fire the events on buttons is making sure that one of the letters in UIButton's title is touched (using the simulator, of course).

I must say that _menuView is hidden behind the other subviews and shown below the cell when a custom accessory button in cell is pressed. It appears by modifying the Y origin and disappears by setting it to 0.0f again.

I think it may be related to the view hierarchy, because I haven’t had any problems in the past by adding buttons directly to the cell. But I’m just guessing here.

How can I make the events on buttons take precedence over the didSelectRowAtIndexPath: method?

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-06-14T13:39:59+00:00Added an answer on June 14, 2026 at 1:39 pm

    Implement

    - (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
    

    And return nil for the indexPath you don’t want selected; this will prevent didSelectRowAtIndexPath from being called on that cell, and (hopefully), your custom action will be called.

    Update: After implementing this myself (adding borders to the buttons), this is what I have.enter image description here

    The code to achieve this (which is different than yours), is as follows:

    CellMenuView.m

        self.backgroundColor = [UIColor blackColor];
        _editButton.layer.borderColor = [UIColor whiteColor].CGColor;
        _editButton.layer.borderWidth = 2;
        _fireButton.layer.borderColor = [UIColor whiteColor].CGColor;
        _fireButton.layer.borderWidth = 2;
    

    UITableViewCell subclass

        // Change in height to make it taller
        _menuView = [[TestBtn alloc] initWithFrame:CGRectMake(0.0f, 20.0f, 320.0f, 60.0f)];
    

    UITableViewController subclass

        self.tableView.rowHeight = 100;
    

    After testing, mine works as expected. If I click within the white squares, the button action is performed as normal, and didSelectRowAtIndexPath is not called. didSelectRowAtIndexPath is only called when I click outside of the buttons.

    I think the issue here might be your button heights/frames, as well as your row height. Add borders to your buttons, to check its clickable area, and increase the height of the button to increase the clickable area.

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

Sidebar

Related Questions

I'm trying out this nice way of customizing grouped UITableViewCell backgrounds: http://code.coneybeare.net/how-to-make-custom-drawn-gradient-backgrounds I've implemented
I'm migrating from customizing my TableViewCells in tableView:cellForRow:atIndexPath: to using a custom UITableViewCell subclass.
I'm customizing my navigation bar using: UIImage *anImage = [[UIImage imageNamed:@theImage] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0,
I was trying to customizing the UIBarButtonItem in Navigation Bar I found that there
I'm customizing a color picker's default showing colors which will be used as background
We are customizing workflow approval form to display the associated list item fields. This
I'm working on customizing a couple of open source projects in ways that are
I am interested in customizing the authentication method for a Joomla website. There is
I am working on customizing a closed source client application. It has a tree
I am customizing N2CMS's database structure, and met with an issue. The two classes

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.