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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:37:34+00:00 2026-05-24T23:37:34+00:00

I’m making an app that needs three buttons in each tableview cell. I tried

  • 0

I’m making an app that needs three buttons in each tableview cell. I tried just adding the buttons to the cell using addSubview in cellForRowAtIndexPath: but this resulted in slow/janky scrolling with more than 6 or 7 rows.

I did some research online and have followed Apple’s example of subclassing the UITableViewCell and drawing everything in drawRect. I can get text and images to draw perfectly, using drawAtPoint but this doesn’t appear to work for UIButtons.

Adding the button as a subview of [self contentView] (in my subclasses drawRect) just results in even worse scroll lag than before.

Does anyone know how to get a button to draw properly within my UITableViewCell subclass?

Getting this right is crucial to the entire app so any help would be greatly appreciated!

UPDATE: Here is the code used for for tableView:cellForRowAtIndexPath

static NSString *CellIdentifier = @"CustomCell";

AHCustomCell * cell = (AHCustomCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
    AHCustomCell * customCell = [[[AHCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    customCell.frame = CGRectMake(0.0, 0.0, 320.0, 55.0);
    cell = customCell;
}
  • 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-24T23:37:34+00:00Added an answer on May 24, 2026 at 11:37 pm

    The following code gives three buttons and no jaggy scrolling. Using tags, you can reset the text of the buttons depending on the row. This is illustrated for button 1 (which adjusts its title according to the row number). The button1Pressed: method illustrated figures out what row the button press came from. Hope this will be helpful.

    - (UITableViewCell *)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString* cellIdentifier = @"Cell";
    
        // see if there's a cell available to recylce
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    
        if (!cell)
        {
            // there's no cell to recycle, so make a new one
            // add three buttons to it and tag them so we can alter their contents later
    
            cell = [[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:cellIdentifier];
    
            UIButton* button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
            [button1 setTitle:@"Button 1" forState:UIControlStateNormal];
            [button1 setFrame:CGRectMake(4.0, 15.0, 110, 30.0)];
            [button1 setTag:101];
            [button1 addTarget:self action:@selector(button1Pressed:) forControlEvents:UIControlEventTouchUpInside];
            [[cell contentView] addSubview:button1];
    
            UIButton* button2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
            [button2 setTitle:@"Button 2" forState:UIControlStateNormal];
            [button2 setFrame:CGRectMake(120.0, 15.0, 80.0, 30.0)];
            [button2 setTag:102];
            [button1 addTarget:self action:@selector(button2Pressed:) forControlEvents:UIControlEventTouchUpInside];
            [[cell contentView] addSubview:button2];
    
            UIButton* button3 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
            [button3 setTitle:@"Button 3" forState:UIControlStateNormal];
            [button3 setFrame:CGRectMake(210, 15.0, 80.0, 30.0)];
            [button3 setTag:103];
            [button3 addTarget:self action:@selector(button3Pressed:) forControlEvents:UIControlEventTouchUpInside];
            [[cell contentView] addSubview:button3];
    
        }
    
        // either on a recycled cell or on the cell just created, set the contents
    
        UIButton* button1 = (UIButton*)[[cell contentView] viewWithTag:101];
        [button1 setTitle: [NSString stringWithFormat:@"Button 1 - %d", [indexPath row]] forState:UIControlStateNormal];
    
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
        return cell;
    }
    
    
    
    - (void) button1Pressed: (UIButton*) button
    {
       CGPoint buttonCentre = [button convertPoint:[button center] toView:[self tableView]];
    
        NSLog(@"Button 1 Pressed on row %d", [[[self tableView] indexPathForRowAtPoint:buttonCentre] row]);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into

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.