In xcode 4.3.1, target iPad 5.1 simulator
use ARC, don't use Storyboard
in ViewController.h
#import <UIKit/UIKit.h> @interface ViewController : UIViewController { NSObject *anObject; NSObject *anotherObject; } -(void) makeObjects; @end
in ViewController.m add
-(void) makeObjects{ anObject = [[NSObject alloc] init]; anotherObject = [[NSObject alloc] init]; int a = 1; }
in AppDelegate.m add a line
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]; self.window.rootViewController = self.viewController; [self.viewController makeObjects]; // ADD THIS LINE <-------- [self.window makeKeyAndVisible]; return YES; }
in ViewController.m, set a breakpoint at
anObject = [[NSObject alloc] init];
run
Are you using the LLDB debugger? Currently it doesn't give you correct values on iVars in the simulator. Switch back to GDB and you'll find the correct values reported. I discovered this behavior here: UIViewController subclass can't assign instance variable .
And yes, I reported a bug. I got a response back from Apple stating it is a known issue.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.