Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom UIAlertView: How to prevent an Objective-C object to be released automatically by ARC or How to retain an object manually in an ARC environment
    primarykey
    data
    text
    <p>I have written an UIAlertView like class (GOAlertView) just to have the same functionality of iOS7 beta 4's well known property 'contentView', which has been removed in iOS7 beta 5, in an other words, I am trying to create a custom AlertView. But with Apple's UIAlertView its possible to have a code like this:</p> <pre><code>[[[UIAlertView alloc] initWithTitle:@"Hello" message:@"Are you good programmer" delegate:self cancelButtonTitle:@"No comments" otherButtonTitles:@"Ya", @"Hee :)", nil] show]; </code></pre> <p><strong>Important:</strong> Here I am not holding any strong reference of UIAlertView like </p> <pre><code>@property (strong, nonatomic) UIAlertView *alertView; </code></pre> <p>rather I am using it on the fly. Not only that but also I can the delegate message as well.</p> <p><strong>Problem:</strong> But with my own GOAlertView (which is not a subclass of UIAlertView) I can's show my AlertView because it has been deallocated immediately. But if I hold the strong reference like above mention way, it works. But I can't use it on the fly.</p> <p>I have seen an example from: <a href="https://github.com/TomSwift/TSAlertView/blob/master/TSAlertView/TSAlertView.m" rel="nofollow">https://github.com/TomSwift/TSAlertView/blob/master/TSAlertView/TSAlertView.m</a></p> <p>where the programmer says inside the method '- show' "$important - the window is released only when the user clicks an alert view button" and he is releasing the 'window' object by himself. But I can't do so, because I am working in ARC enabled environment, and I don't even want to disable it (my be only for the GOAlertView).</p> <p>Can any one give an explanation or may be a same example to have a contentView like property...?</p> <p><strong>simulated code:</strong></p> <p><strong>GOAlertView.m is:</strong></p> <pre><code>#import "GOAlertView.h" @interface GOAlertView () @property (strong, nonatomic) UIWindow *window; @end @implementation GOAlertView - (void)show { UIViewController *vc = [UIViewController new]; self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].applicationFrame]; [self.window setWindowLevel:UIWindowLevelStatusBar]; [self.window setRootViewController:vc]; UIView *view = [[UIView alloc] initWithFrame:CGRectMake(60, 100, 200, 160)]; [view setBackgroundColor:[UIColor purpleColor]]; [vc.view addSubview:view]; [self.window setHidden:NO]; } </code></pre> <p>and <strong>GOViewController.m is:</strong></p> <pre><code>#import "GOViewController.h" #import "GOAlertView.h" @interface GOViewController () @property (strong, nonatomic) GOAlertView *alertView; @end @implementation GOViewController - (void)viewDidLoad { [super viewDidLoad]; // [self setAlertView:[[GOAlertView alloc] init]]; // [self.alertView show]; [[[GOAlertView alloc] init] show]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end </code></pre> <p>here, if I use </p> <pre><code>[self setAlertView:[[GOAlertView alloc] init]]; [self.alertView show]; </code></pre> <p>instead </p> <pre><code>[[[GOAlertView alloc] init] show]; </code></pre> <p>to present, I can see a purple color square on the screen.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload