Dealloc in a view

Discussion in 'iOS Development' started by Chicken, Feb 15, 2009.

  1. Chicken

    Chicken Retired Moderator

    Joined:
    Feb 17, 2008
    Messages:
    2,494
    Likes Received:
    7
    Device:
    iPhone 5S
    People might say that if I don't know how to do this I shouldn't be programming. When I remove a view from the superview does it automatically run the dealloc function in that views class ? Or do I do it manually something like this ?

    Code:
    - (IBAction)myAction {
                 [self addSubview:SecondView.view];
                 [self removeFromSuperView];
                 [self dealloc];
    }
    do I need to use self dealloc or will it automatically do itself. This sounds like a stupid question but I don't know.
  2. NolesFans

    NolesFans New Member

    Joined:
    Sep 23, 2008
    Messages:
    404
    Likes Received:
    0
    Device:
    iPod touch
    that dealloc call would made the apps crash.
  3. Chicken

    Chicken Retired Moderator

    Joined:
    Feb 17, 2008
    Messages:
    2,494
    Likes Received:
    7
    Device:
    iPhone 5S
    As I found out 5 minutes after I posted this oh well thanks for helping
  4. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    Never call a dealloc method. Doing so will result in a double free error and will crash your application. Just call [yourObject release];

    This is unless, of course, you have zombies enabled, but you should never release an app that could contain zombies.
  5. Chicken

    Chicken Retired Moderator

    Joined:
    Feb 17, 2008
    Messages:
    2,494
    Likes Received:
    7
    Device:
    iPhone 5S
    ok thanks skylar this has helped a lot my app is nearly finished 1 more question.

    Code:
     - (void)alertSheet:(UIAlertView *)alertSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    	if (buttonIndex == 0) {
    		[self dismissModalViewControllerAnimated:TRUE];
    		
    	}
    }

    it should dismiss my view controller when I press the first button correct ?
  6. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    If you have a modal view controller present, that message will dismiss it.
  7. Chicken

    Chicken Retired Moderator

    Joined:
    Feb 17, 2008
    Messages:
    2,494
    Likes Received:
    7
    Device:
    iPhone 5S
    yes my modal view controller is present but when I press the first button it just dismisses the alert view any thoughts ?
  8. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    set the delegate of your alert view to whatever class that selector is in.
  9. Chicken

    Chicken Retired Moderator

    Joined:
    Feb 17, 2008
    Messages:
    2,494
    Likes Received:
    7
    Device:
    iPhone 5S
    ok I'll try that when I have time

Share This Page