title: Accessing instance variables from UITableView delegate methods
body: <p><strong>Question:</strong></p>
  
  <p>I'm trying to access a variable from the UITableView <code>tableView:didSelectRowAtIndexPath:</code> delegate method. The variable can be accessed from the data source methods, but when I try to access it from delegate methods such as this one, the app crashes.</p>
  
  <p>I declare the variable in my .h file, and initialise it in .m file in the <code>applicationDidFinishLaunching</code> method. I haven't declared any accessors/mutators.</p>
  
  <p>The weird thing is that the problem doesn't occur if I declare the variable like this:</p>
  
  <pre><code>helloWorld = @"Hello World!";
  </code></pre>
  
  <p>...but it does if I declare the variable like this:</p>
  
  <pre><code>helloWorld = [NSString stringWithFormat: @"Hello World!"];
  </code></pre>
  
  <p>Any ideas on what may be going on here? What am I missing?</p>
  
  <p><strong>Full code:</strong></p>
  
  <p>UntitledAppDelegate.h:</p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  
  @interface UntitledAppDelegate : NSObject &lt;UIApplicationDelegate, UITableViewDelegate, UITableViewDataSource&gt;  {
      UIWindow *window;
      NSString *helloWorld;
  }
  
  @property (nonatomic, retain) IBOutlet UIWindow *window;
  
  @end
  </code></pre>
  
  <p>UntitledAppDelegate.m:</p>
  
  <pre><code>#import "UntitledAppDelegate.h"
  
  @implementation UntitledAppDelegate
  
  @synthesize window;
  
  
  - (void)applicationDidFinishLaunching:(UIApplication *)application {
  
      helloWorld = [NSString stringWithFormat: @"Hello World!"];
  
      NSLog(@"helloWorld: %@", helloWorld); // As expected, logs "Hello World!" to console.
  
      [window makeKeyAndVisible];
  }
  
  - (void)dealloc {
      [window release];
      [super dealloc];
  }
  
  - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
       return 1;
  }
  
  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
      static NSString *MyIdentifier = @"MyIdentifier";    
      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; 
      if (cell == nil) {
          cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] autorelease];
      }   
      cell.textLabel.text = @"Row";
      return cell;
  }
  
  - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
      NSLog(@"helloWorld: %@", helloWorld); // App crashes
  }
  
  @end
  </code></pre>