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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:51:37+00:00 2026-05-31T21:51:37+00:00

I have a view where I am showing image and image name in a

  • 0

I have a view where I am showing image and image name in a grid view. As shown in the image.

show image

Now for the same I am taking one UIButton with image as background and UILabel and positioning it accordingly on the screen. Now when I press on the UIButton, it shows the UIActionSheet with option to delete, view and cancel. Now problem comes here. When I press Delete for only one record, the record gets deleted, but if more that one records are there, then gives issues in deleting that it shows the deleted record.

To Add UIButton and UILabel:

-(void)showImageFrame
{
    int FrameWidth = 190;
    int Frameheight = 196;
    int FrameX;
    int FrameY;

    int lblWidth = 190;
    int lblHeight = 40;
    int lblX,lblY;

    settButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [settButton setImage:[UIImage imageNamed:@"Picture frame.png"] forState:UIControlStateNormal];
    [settButton addTarget:self action:@selector(pressSelectedImage:) forControlEvents:UIControlEventTouchDown];

    btnInnerImg = [UIButton buttonWithType:UIButtonTypeCustom];
    [btnInnerImg addTarget:self action:@selector(pressSelectedImage:) forControlEvents:UIControlEventTouchDown];

    lblImgName = [[UILabel alloc]init];
    lblImgName.font = [UIFont boldSystemFontOfSize:30];
    lblImgName.textAlignment = UITextAlignmentCenter;
    lblImgName.textColor = [UIColor whiteColor];
    lblImgName.backgroundColor = [UIColor clearColor];


    for(int i = 0;i<cnt1;i++)
    {
        [settButton setTag:i];
        img = [[appDelegate.DataArray objectAtIndex:i]valueForKey:@"ProfileImage"];

        [btnInnerImg setImage:img forState:UIControlStateNormal];
        [btnInnerImg setTag:i];

        lblImgName.text = [[appDelegate.DataArray objectAtIndex:i]valueForKey:@"strNameImg"];
        [lblImgName setTag:i];

        if(i==0)
        {
            FrameX = 35;FrameY = 119;btnX = 49;btnY=134;lblX = 35;lblY=337;
        }
        if(i==1)
        {
            FrameX = 289;FrameY = 119;btnX = 303;btnY=134;lblX = 289;lblY=337;
        }
        if(i==2)
        {
            FrameX = 545;FrameY = 119;lblX = 545;lblY=337;btnX = 558;btnY=134;
        }
        if(i==3)
        {
            FrameX = 802;FrameY = 119;lblX = 802;lblY=337;btnX = 816;btnY=134;
        }
        if(i==4)
        {
            FrameX = 35;FrameY = 411;lblX = 35;lblY=629;btnX = 49;btnY=426;
        }
        if(i==5)
        {
            FrameX = 289;FrameY = 411;lblX = 289;lblY=629;btnX = 303;btnY=426;
        }
        if(i==6)
        { 
            FrameX = 545;FrameY = 411;lblX = 545;lblY=629;btnX = 558;btnY=426;
        }
        if(i==7)
        {
            FrameX = 802;FrameY = 411;lblX = 802;lblY=629;btnX = 816;btnY=426;
        }

        [settButton setFrame:CGRectMake(FrameX,FrameY,FrameWidth,Frameheight)];
        [lblImgName setFrame:CGRectMake(lblX,lblY,lblWidth,lblHeight)];
        [btnInnerImg setFrame:CGRectMake(btnX,btnY,btnWidth,btnHeight)];

        [newButtonArray addObject:settButton];
        [self.view addSubview: settButton];
        [self.view addSubview: lblImgName];
        [self.view addSubview: btnInnerImg];
    }
}

To remove the UIButton and UILabel:

-(void)removeImageFrame
{
    [settButton removeFromSuperview];
    [btnInnerImg removeFromSuperview];
    [lblImgName removeFromSuperview];

    settButton = nil;
    btnInnerImg = nil;
    lblImgName = nil;        
}

I don’t want to use UITableviewCell for the grid view. Also what I am doing is that on deleting 1 record, I am removing all the records and reload them again as per record counter. I know I am doing some mistake in removeImageFrame method, but not able to find it. How can I remove the single UIButton with different Tags?

  • 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-31T21:51:38+00:00Added an answer on May 31, 2026 at 9:51 pm

    It would be nice to see a bit more context (the action method and how you get from pressing the button to deleting the button), but here is some advice:

    • Remove all objects from your button array at the start of showImageFrame
    • Create new buttons (with locally declared variables, not an ivar) inside the loop.
    • Don’t use a tag of 0, that is the default tag that all views have
    • When a button is tapped, try to pass this as an argument to the removeImageFrame method – that’s what sender is for.
    • You could also look at background images and foreground images for a single button instead of having what appears to be one button for the frame and one for a picture
    • (unrelated to your problem) try to think of a better way to display a grid than hard coding coordinates. What it the device is rotated?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have data grid view with columns product name and product image and I
I have a view that I am showing. The view appears on the same
I have a portrait view showing a library of images, clicking on an image
I have grid view with three column name, rate, category I am also using
I have a strongly typed Category View, showing all Category (in a grid) ...
I have an image view on which i have included a table view. Now
My idea is to have a view that is showing the user when something
i have view controller which contains a button which show the image library ,if
I have view page with both detailview and gridview the grid view should be
I already have a view box showing the user where to center the 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.