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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:21:19+00:00 2026-06-07T03:21:19+00:00

i have to set some custom size parameters to a UIView according to the

  • 0

i have to set some custom size parameters to a UIView according to the device orientation. i load the UIView which has NOT an own viewcontroller as follows:

in main.h

@property (nonatomic, retain) IBOutlet UIView *socialActionView;

in main.m

@synthesize socialActionView;

.
.
.

socialActionView = [[[NSBundle mainBundle] loadNibNamed:@"SocialActionViewController" owner:self options:nil] objectAtIndex:0];
[self.view addSubview:socialActionView];

if not needed anymore i remove it from the superview with

[self.socialActionView removeFromSuperview];
NSLog(@"%@",self.socialActionView.superview);

the log says (null) after removal

the size adjustments i do like this

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 
{
    if ((self.interfaceOrientation == UIDeviceOrientationPortrait) || (self.interfaceOrientation == UIDeviceOrientationPortraitUpsideDown)){
        if (self.socialActionView != NULL) {
            [self.socialActionView setBounds:CGRectMake(0, 0, 320, 480)];
            [self.socialActionView setCenter:CGPointMake(160, 240)];
            [self.scroll1 setContentSize:CGSizeMake(320, 600)];
            [self.scroll1 setBounds:CGRectMake(0, 0, 320, 428)];
            [self.scroll1 setCenter:CGPointMake(160, 266)];
        }
    } else if((self.interfaceOrientation == UIDeviceOrientationLandscapeLeft) || (self.interfaceOrientation == UIDeviceOrientationLandscapeRight)){
        if (self.socialActionView != NULL) {
            [self.socialActionView setBounds:CGRectMake(0, 0, 480, 320)];
            [self.socialActionView setCenter:CGPointMake(240, 160)];
            [self.scroll1 setContentSize:CGSizeMake(480, 600)];
            [self.scroll1 setBounds:CGRectMake(0, 0, 480, 268)];
            [self.scroll1 setCenter:CGPointMake(240, 186)];
        }
    }
} 

works ok so far until i don´t remove the subview (socialAcitonView) from my main view. cause after that the self.socialActionView is not accessable anymore. i´ve seen a lot of examples here on stackoverflow like

-(IBAction)showPopup:(id)sender {
    if(![[self myView] isDescendantOfView:[self view]]) { 
        [self.view addSubview:[self myView]];
    } else {
        [[self myView] removeFromSuperview];
}

or

-(IBAction)showPopup:(id)sender
{
    if (!myView.superview)
        [self.view addSubview:myView];
    else
        [myView removeFromSuperview];
}

or

if (!([rootView subviews] containsObject:[self popoverView])) { 
    [rootView addSubview:[self popoverView]];
} else {
    [[self popoverView] removeFromSuperview];

}

or

-(IBAction)showPopup:(id)sender {
    if([[self myView] superview] == self.view) { 
        [[self myView] removeFromSuperview];           
    } else {
        [self.view addSubview:[self myView]];         
    }
}

but none of them works. the debugger always throws an exception cause of bad access. what (from my point of view) means the object does not exist any more. but how can the logger access it after i´ve removed it from the superview and say (null)?

i know it would have been better to give the view an dedicated view controller and put didRotateFromInterfaceOrientation there so i don´t have to check if the socialActionView is there. anyhow i´d like to ask if there is a way how i can check of the UIView is (null) nor not. before i change all my code to a view/viewcontroller couple.

any hints appreciated!

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

    You are making it a retained property and then bypassing the retain attribute when you do this:

    socialActionView = [[[NSBundle mainBundle] loadNibNamed:@"SocialActionViewController" owner:self options:nil] objectAtIndex:0];
    

    If you make that self.socialActionView = ... your property should hold its reference even after the view is removed from the subviews array.

    (In fact, I’d recommend changing your synthesize statement to @synthesize socialActionView = _socialActionView; and putting a self.socialActionView wherever the compiler complains about that symbol.)

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

Sidebar

Related Questions

I have a JTable using a custom DefaultTableModel which has some Booleans in the
I have one AlertDialog which is working fine.I have set some background images to
I have a custom UIView, which I have placed using Xcode (4). I need
I have a custom UIView that generates a set of subviews and display them
I have some custom user controls in my .net winforms program that do not
I have an android gridview which i'm using some custom scrolling going on in,
I have a custom control of class DottedCanvas inherited from Canvas, which contains some
In my init I have set some variables and one animate that uses those
I have to set some routing rules in my php application, and they should
I have some set of xml generated via xmlserialization of some WCF messages. Now

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.