Created
May 17, 2014 08:10
-
-
Save aug2uag/5378c17c8874e5dbca10 to your computer and use it in GitHub Desktop.
demonstration that removing object from superview requires re-alloc of that object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ViewController.m | |
// remove from superview demo | |
// | |
// Created by Rex Fatahi on 5/17/14. | |
// Copyright (c) 2014 aug2uag. All rights reserved. | |
// | |
#import "ViewController.h" | |
@interface ViewController () | |
{ | |
UIView* aView; | |
} | |
@end | |
@implementation ViewController | |
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
// Do any additional setup after loading the view, typically from a nib. | |
aView = [[UIView alloc] initWithFrame:CGRectMake(40, 40, 240, 240)]; | |
aView.backgroundColor = [UIColor redColor]; | |
[self.view addSubview:aView]; | |
UIButton* aButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; | |
[aButton setTitle:@"do it" forState:UIControlStateNormal]; | |
[aButton addTarget:self action:@selector(doIT:) forControlEvents:UIControlEventTouchUpInside]; | |
aButton.frame = CGRectMake(20, self.view.bounds.size.height - 64, 280, 44); | |
[self.view addSubview:aButton]; | |
} | |
- (void)doIT:(UIButton *)sender | |
{ | |
if (!sender.selected) { | |
[aView removeFromSuperview]; | |
} else { | |
[self.view addSubview:aView]; | |
} | |
} | |
- (void)didReceiveMemoryWarning | |
{ | |
[super didReceiveMemoryWarning]; | |
// Dispose of any resources that can be recreated. | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment