Skip to main content

Posts

Showing posts with the label automatic-ref-counting

How do I replace weak references when using ARC and targeting iOS 4.0?

I've begun developing my first iOS app with Xcode 4.2, and was targeting iOS 5.0 with a "utility application" template (the one that comes with a FlipsideViewController). I read that since ARC is a compile-time feature, it should be compatible with iOS 4 as well, so I attempted to target my app to 4.3, and try compiling it. When I do so, I get this error: FlipsideViewController.m: error: Automatic Reference Counting Issue: The current deployment target does not support automated __weak references It is referencing this line: @synthesize delegate = _delegate; That variable is declared as: @property (weak, nonatomic) IBOutlet id <FlipsideViewControllerDelegate> delegate; I understand that "weak references" are not supported in iOS 4, but I don't really understand why I would want to use a weak reference to begin with, nor can I figure out how I would rewrite things to avoid using it, while still taking advantage of ARC (after all, it's su

ViewController gets deallocated which leads to crash

I have a view in my storyboard which I assigned an identifier called "MainView". However if I add its view to the subview, everything that follows produces a crash (e.g. pressing a button) MainViewController *mvc = [self.storyboard instantiateViewControllerWithIdentifier:@"MainView"]; [self.view addSubview:mvc.view]; This is the action triggered by the button : (MainViewController.h) -(IBAction)showUsername:(id)sender{ [testLabel setText:@"username"]; } and the crash log : -[MainViewController performSelector:withObject:withObject:]: message sent to deallocated instance 0x44e0810 I use ARC.