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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:06:43+00:00 2026-05-23T01:06:43+00:00

I am creating a section view programmatically and I have a UIButton delete also

  • 0

I am creating a section view programmatically and I have a UIButton “delete” also programmatically assigned. However, when the button is pressed, I’d like to delete that section from my tableview. How should I go about doing this?

Here is the code that creates the section header view:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView* customView;
    if (Cart.myOrderSummaryRow == 0)
    {
        // create the parent view that will hold header Label
        customView = [[UIView alloc] initWithFrame:CGRectMake(10.0, 0.0, 300.0, 44.00)];
        customView.backgroundColor = [UIColor grayColor];

        //food item label
        UILabel * _headerLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        _headerLabel.backgroundColor = [UIColor clearColor];
        _headerLabel.opaque = YES;
        _headerLabel.textColor = [UIColor blackColor];
        //_headerLabel.highlightedTextColor = [UIColor whiteColor];
        _headerLabel.font = [UIFont boldSystemFontOfSize:14];
        _headerLabel.frame = CGRectMake(40.0, 0.0, 300.0, 44.0);

        NSMutableString *header = [[[NSMutableString alloc] initWithCapacity:20] autorelease];
        FoodItem *tmpFoodItem = [Cart.foodItemsArray objectAtIndex:section];
        [header appendString:tmpFoodItem.foodName];
        _headerLabel.text = header;
         [customView addSubview:_headerLabel];

        //price label
        UILabel * _priceLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        _priceLabel.backgroundColor = [UIColor clearColor];
        _priceLabel.opaque = YES;
        _priceLabel.textColor = [UIColor blackColor];
        //_headerLabel.highlightedTextColor = [UIColor whiteColor];
        _priceLabel.font = [UIFont boldSystemFontOfSize:14];
        _priceLabel.frame = CGRectMake(200.0, 0.0, 300.0, 44.0);

        NSMutableString *price = [[[NSMutableString alloc] initWithCapacity:20] autorelease];
        [price appendString:@"$"];
        [price appendString:tmpFoodItem.foodPrice];
        _priceLabel.text = price;
        [customView addSubview:_priceLabel];

        //delete button
        UIButton *deleteButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];    
        deleteButton.frame = CGRectMake(260.0, 10, 40.0, 20.0); // x,y,width,height
        [deleteButton setTitle:@"-" forState:UIControlStateNormal];
        [deleteButton addTarget:self 
                             action:@selector(foodDeleteButtonPressed:)
               forControlEvents:UIControlEventTouchDown];        

        [customView addSubview:deleteButton];
    } else {
        customView = nil;
    }

    return customView;
}

Here is how the UITableView looks –

enter image description here

As you can see the sections are in grey and there is a button inside the section for deleting the section itself. The non highlighted part is the row. The sections correspond to food items and the rows correspond to side items. There are different delete buttons for sections and rows.

  • 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-23T01:06:44+00:00Added an answer on May 23, 2026 at 1:06 am

    I think you should try the button.tag condition. It might be help you something as like given below.

    Example

    if((((UIButton *)myView).tag == REPLY_BADGE_TAG) || (((UIButton *)myView).tag == FAVORITE_BADGE_TAG))
    {
         NSLog(@"tag: %d",((UIButton *)myView).tag);    
    } else {
        ((UIButton *)myView).hidden = NO;
        ((UIButton *)myView).tag = indexPath.row;
    }  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a page that allows users access to a certain section of
I am creating a page that allows users access to a certain section of
Let's say I have a Statistic view that will display on different pages. Without
I have an app that allows the user to move from a list of
I have an ASP.NET MVC 2 project that renders conventional strongly typed pages, but
I have a grouped UITableView in my UIViewController class and I'm finding that at
I'm creating a humble web browser-game in PHP. I'm making a robbery section... I
I add header and footer view while creating my table. What I want to
I'm trying to incorporate and modify the expanding section headers from WWDC 2010 vol128
How would you structure the below page in Codeigniter? I thought about creating seperate

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.