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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:07:32+00:00 2026-06-09T03:07:32+00:00

I have a simple application where i add UIButton programmatically as follow for(int i=0;i<[self.contentList

  • 0

I have a simple application where i add UIButton programmatically as follow

    for(int i=0;i<[self.contentList count];i++)
    {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        [button addTarget:self action:@selector(buttonSelection:)forControlEvents:UIControlEventTouchDown];
        [button setTitle:[ [contentList objectAtIndex:i] valueForKey:@"nameKey"]  forState:UIControlStateNormal];
        button.tag=i+kButtonTagOffset;
        [self.view insertSubview:button atIndex:0];
       // [button release];

    }

Then Accessing it when view change its orientation as follow to adjust its position as follow

  for (int row = 0; row < Portrait_TILE_ROWS; ++row)
    {
        for (int col = 0; col < Portrait_TILE_COLUMNS; ++col)
        {
            int index = (row * Portrait_TILE_COLUMNS) + col;
            CGRect frame = CGRectMake(LandScape_TILE_MARGIN + col * (LandScape_TILE_MARGIN + LandScape_TILE_WIDTH),
                                      LandScape_TILE_MARGIN + row * (LandScape_TILE_MARGIN + LandScape_TILE_HEIGHT),
                                      LandScape_TILE_WIDTH, LandScape_TILE_HEIGHT);

            UIButton *tmb= (UIButton *)[self.view viewWithTag:index+kButtonTagOffset];
            if([tmb isKindOfClass:[UIButton class]]) //isKindOfClass
            {   
                [  [self.view viewWithTag:index+kButtonTagOffset] setFrame:frame];

            }

        }
    }

My First question is why i get EXC_BAD_ACCESS error if i release the UIBUtton after adding to subview and it only happens on the device not the simulator .I thought when adding to a subview the retain count of the objects goes up by one and accessing it later won’t raise that ERROR any idea ?

How i can figure out within the xcode debugger what object and where that EXC_BAD_ACCESS exception
is raised i figured it out by simply commenting parts of the code !!!

Thanks
M

  • 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-09T03:07:33+00:00Added an answer on June 9, 2026 at 3:07 am

    You need to reread the basics of memory management and cocoa naming conventions. You didn’t call alloc, copy, or retain on it…so releasing it is incorrect. That constructor returns an autoreleased object. If this concept is difficult for you, please switch to ARC.

    As for figuring out which line the error is on -> "Run > Stop on Objective-C exception" in Xcode 4?

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

Sidebar

Related Questions

I have a simple jsp/servlet application and I want to add AJAX feature to
I have a really simple blog application and I want to add a really
I have created blank C#/XAML Windows 8 application. Add simple XAML code: <Page x:Class=Blank.MainPage
I have simple JSF2 application running on glashfish 3.1. I want to add a
I have a simple silverlight application and i need to add the web browser
I have a simple WPF application with a menu. I need to add menu
Let's say I have a simple application. It tries to add a new entry
I have a simple web application (non sharepoint) in which i want to add
I have in mind one simple application, but I would like to add some
I have a very simple application installer that needs to add an action to

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.