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

  • Home
  • SEARCH
  • 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 7825585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:04:04+00:00 2026-06-02T09:04:04+00:00

i have a grouped tableview which contains 3 sections,i want to add different buttons

  • 0

i have a grouped tableview which contains 3 sections,i want to add different buttons for each section,,i have 5 cells in the first section,and i want to add only 3 unbuttons in the 2nd ,3r an 4th cell.my code look like this

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 3;
}


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if(section == 0)
        return [_arayfirstrow count];
    else if(section == 1)
        return [_arraysecondrow count];
    else  if(section == 2)
        return [_arraythirdrow count];
}
   // Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";
   // static NSUInteger nTag = 100;
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
        cell.textLabel.font = [UIFont fontWithName:@"Georgia"size:20.0];



    }

    // Set up the cell...
    if(indexPath.section == 0){
            cell.textLabel.text = [_arayfirstrow objectAtIndex:indexPath.row];
        NSString *imageName = [_arayfirstrowimg objectAtIndex:indexPath.row];
        cell.imageView.image = [UIImage imageNamed:imageName];

**//when i add below code for inserting button on the first section ,it successfully adds the button,but i don't need button for 1st and 5th cell..ans also it crashes when i tap the button for 2 or three time**

  CGRect buttonRect = CGRectMake(210, 25, 65, 25);
     UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        button.frame = buttonRect;
        // set the button title here if it will always be the same
        [button setTitle:@"Action" forState:UIControlStateNormal];
        button.tag = 1;
        [button addTarget:self action:@selector(myAction:) forControlEvents:UIControlEventTouchUpInside];

        [cell.contentView insertSubview:button atIndex:0];



       // [usernamebutton release];

    }else if(indexPath.section == 1){
        cell.textLabel.text = [_arraysecondrow objectAtIndex:indexPath.row];
    }
    else if(indexPath.section == 2)
    {
        cell.textLabel.text = [_arraythirdrow objectAtIndex:indexPath.row];

    }
    return cell;
}

is there any solution to solve this.
thanks in advance.

  • 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-02T09:04:12+00:00Added an answer on June 2, 2026 at 9:04 am

    You can try like this:

    if(indexPath.section == 0)
    {
        if(indexPath.row == 1||indexPath.row == 2||indexPath.row == 3)
        {
            CGRect buttonRect = CGRectMake(210, 25, 65, 25);
            UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
            button.frame = buttonRect;
            // set the button title here if it will always be the same
            [button setTitle:@"Action" forState:UIControlStateNormal];
            button.tag = 1;
            [button addTarget:self action:@selector(myAction:) forControlEvents:UIControlEventTouchUpInside];
            [cell.contentView addSubView:button atIndex:0];
        }
    }
    

    Have you defined the method myAction:? If not, it might be crashing your application.

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

Sidebar

Related Questions

I have a grouped tableView with 5 sections and i want to add buttons
I have a grouped tableview with two sections, and I want the cells (in
I have a grouped table with 3 sections, each section with a title. The
I have one problem with two sections in UITableview grouped style. First section having
I have Grouped Table View in which I want to display Contact details. But
I have a grouped UITableView which displays a number of cells, which includes both
I have a grouped UITableView with many sections, however, I want to iterate through
I have a grouped UITableView that contains several cells (just standard UITableViewCell s), all
I have a grouped tableview that is populated with XML data in one section.
I have a grouped UITableView with some sections (with an header title). I want

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.