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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:59:47+00:00 2026-05-16T21:59:47+00:00

I am trying to create a list of options with check boxes. I am

  • 0

I am trying to create a list of options with check boxes. I am using UITableView and adding custom type buttons to the table as checkboxes.

My code for cellForRowAtIndexPath method is pasted below:

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

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
CGRect a=CGRectMake(0, 0, 310, 32);
UIImageView *aImg=[[UIImageView alloc] initWithFrame:a];
UIImageView *bImg=[[UIImageView alloc] initWithFrame:a];
aImg.image=[[[Resources getResources] getImageLoader] getMainMenuUnselectedImage];
bImg.image=[[[Resources getResources] getImageLoader] getLiveScoreSmallBg];
[aImg setContentMode:UIViewContentModeScaleToFill];
[bImg setContentMode:UIViewContentModeScaleToFill];
cell.backgroundView = [[UIView alloc] initWithFrame:a];
[cell.backgroundView addSubview:aImg];
cell.selectedBackgroundView=bImg;
cell.font = [UIFont boldSystemFontOfSize:16];
cell.selectedTextColor = [UIColor blackColor];
UIImage *checked = [UIImage imageNamed:@"check_filled.png"];
UIImage *unchecked = [UIImage imageNamed:@"check_empty.png"];
UIButton *button = [[UIButton buttonWithType:UIButtonTypeCustom] initWithFrame:CGRectMake(3, 3, 30, 30)];
[button addTarget:self action:@selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside];
[button setImage: [UIImage imageNamed:@"check_filled.png"] forState: UIControlStateSelected];
[button setImage: [UIImage imageNamed:@"check_empty.png"] forState: UIControlStateNormal];
[button setEnabled:YES];
button.tag = indexPath.row;
[button setUserInteractionEnabled:YES];
[cell.contentView addSubview:button];

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(40, 3, 250, 17)];
label.font = [UIFont boldSystemFontOfSize:15]; 
label.backgroundColor = [UIColor clearColor];
label.text = [teamsList objectAtIndex:indexPath.row];
[cell.contentView addSubview:label];

    [button release];
[label release];
[aImg release];
[bImg release];

return cell;
}

The problem is that when I run the program, the screen appears without buttons. Also, when I click any row, the program crashes.

  • 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-16T21:59:47+00:00Added an answer on May 16, 2026 at 9:59 pm

    There’re some problems with your code which may be not relevant to your problem, but still…

    1. You create cell contents each time cell is reused – so if you scroll your table back and forth the reused cells will contain multiple identical subviews – that’s not what you want. To fixed that you must move creating contents to the creating cell block:

      if (cell == nil) {
          cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
          // Create cell contents here!
          ...
      }
      ...
      
    2. You must not release your button – since you create it with convenience method button is autoreleased

      button = [[UIButton buttonWithType:UIButtonTypeCustom] 
                           initWithFrame:CGRectMake(3, 3, 30, 30)];
      
    3. This line may also cause problems:

      [button addTarget:self action:@selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside];
      

      Here you set selector that receives no parameters. If your buttonPressed method declared is (most common way)

      - (void) buttonPressed:(id)sender;
      

      Then you must create selector as @selector(buttonPressed:) to indicate that it actually takes 1 parameter

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

Sidebar

Related Questions

I am trying to create a list of a certain type. I want to
ok so I am trying to dynamically create a select list using javascript, basically
I am trying to create a dynamic set of dropdown boxes, using jQuery/AJAX and
I'm trying to create an application that can show a list of options from
Basically, I'm trying to create a dynamic group of check boxes that are keyed
I am trying to create a list where I want users to enter data
I'm trying to create a list of permutations of a list, such that, for
I'm trying to create UL list with images and descriptions. With 5 items in
I'm trying to create a list, with each <li> on one row. My problem
I'm trying to create a list of tasks that I've read from some text

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.