Note that there are some explanatory texts on larger screens.

plurals
  1. POUIView reference returns NULL pointed ARC enabled
    primarykey
    data
    text
    <p>I have ARC enabled so I am unsure as to why my reference is null.</p> <p>My view controller instantiates a UIView ‘<strong>theGrid</strong>’ as soon as the view is loaded. </p> <p>Later I have switch inside another class (MyOtherClass) that calls the UIViewContoller <code>- (void) updateTheGrid:(id)sender</code> method, that method is called as per the NSLog, but when I output the UIView to see if it is there, its returns null. </p> <p>What am I doing wrong? It was my impression that ARC keeps up with everything. I feel like my trouble is coming from mm "MyOtherClass" when I <code>ViewController * vc = [[ViewController alloc] init];</code> because I feel like that is just creating a new instance. But if that is the case, how am i suppose to reference the old instance and call the method?</p> <p><strong>NSLOG OUTPUT</strong></p> <pre><code>[28853:c07] Intial Grid: &lt;GridView: 0x8e423b0; frame = (0 0; 768 1024); layer = &lt;CALayer: 0x8e43780&gt;&gt; [28853:c07] Update The Grid (null) </code></pre> <p><strong>GridView.h</strong></p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @interface GridView : UIView - (void) gridUpdated; @end </code></pre> <p><strong>GridView.m</strong></p> <pre><code>#import "GridView.h" @implementation GridView - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { // Initialization code NSLog(@"initWithFrame"); } return self; } - (void)drawRect:(CGRect)rect{ NSLog(@"Grid Draw Rect"); } - (void) gridUpdated { NSLog(@"GRID VIEW.m : Grid update called"); [self setNeedsDisplay]; } @end </code></pre> <p><strong>ViewController.h</strong></p> <pre><code>#import &lt;UIKit/UIKit.h&gt; #import "GridView.h" @interface ViewController : UIViewController { GridView *theGrid; } @property (strong, retain) GridView * theGrid; - (void) updateTheGrid : (id) sender; @end </code></pre> <p><strong>ViewController.m</strong></p> <pre><code>#import "ViewController.h" #import "GridView.h" @interface ViewController () {} @end @implementation ViewController @synthesize theGrid; - (void)viewDidLoad { [super viewDidLoad]; //draw the grid theGrid = [[GridView alloc] initWithFrame:self.view.frame]; NSLog(@"Intial Grid: %@", theGrid); [self.view addSubview:theGrid]; } - (void) updateTheGrid : (id) sender{ NSLog(@"Update The Grid %@", theGrid); [theGrid gridUpdated]; } @end </code></pre> <p><strong>MyOtherClass.m</strong></p> <pre><code>- (void) mySwitch : (id) sender { ViewController * vc = [[ViewController alloc] init]; [vc updateTheGrid:sender]; } </code></pre>
    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.
 

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