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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:13:34+00:00 2026-05-26T21:13:34+00:00

I want to load a view dynamically on click of a button. Lets say

  • 0

I want to load a view dynamically on click of a button.

Lets say view is ‘MyView’

I declared it as

IBOutlet UIView *myView;

and connected it via interface builder from a myView.xib made.

I did not set property and synthesize for this view

Now what i want is to allocate this view a memory on click of a button

so i tried in button pressed method of my viewController

(void) buttonPressed1{
   myView = myView = [[[NSBundle mainBundle] loadNibNamed:@"MyView" owner:self options:nil] objectAtIndex:0];
   myView.frame = CGRectMake(30, 40, 200, 200);
   [self.view addSubview:myView];
}

It was Successfully loaded. 🙂

Now i want to access this view in other button click..

so i wrote

-(IBAction) buttonPressed2:(id)sender
{
    myView.alpha = 0;
    [myView release];   
}

so when i run this —it works ok

on buttonPressed it adds that view on other click it fades out and releases that view.

But now when i again click on button to add view it says

modifying layer that is being finalized - 0x6807b60

then on clicking button 2 , it crashes…

Basically my requirement is to keep that view in memory only when it is used after it has been used, it should be deallocated..

so is above approach is good one or there is any other way to do it…

and what does that error mean????

! more query is

Here in above case….

Memory to myView is allocated at run time on click of button ????….

As when i am testing this via instrument in xcode, there is no allocations showing in graph on button click…

so please help me out…

Please help..

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-05-26T21:13:35+00:00Added an answer on May 26, 2026 at 9:13 pm

    When you are releasing view : [myView release]; it is not removed from superview. Moreover : you should not release it as it was created as autoreleased object.

    The solution could be next:

    (void) buttonPressed1{
      if (myView)
      {
          [myView removeFromSuperview];
      }
      myView = [[[NSBundle mainBundle] loadNibNamed:@"MyView" owner:self options:nil] objectAtIndex:0];
      myView.frame = CGRectMake(30, 40, 200, 200);
      [self.view addSubview:myView];
    }
    -(IBAction) buttonPressed2:(id)sender
    {
        myView.alpha = 0;
        //[myView release];   
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on an iOS app where I want to load one view if
I want to load some data from mysql into my cocoa application view before
I'm writing a simple CMS. I want to be able to load a View,
I want to load one or more DLLs dynamically so that they run with
I want to load a desktop application, via reflection, as a Control inside another
I want to load the data into session so that when the next button
I want to load a table view with cells. In between cells I should
I want to create uibuttons dynamically. so i for loop to create button with
I want to load a second View at the beginning of a program. I
I have a tree view control build dynamically. i want to change color of

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.