Objective-C和Xcode的奇怪的行为
问题描述:
在Xcode 4.3.1,目标的iPad 5.1模拟器Objective-C和Xcode的奇怪的行为
- 创建单个视图应用
使用ARC,在视图控制器不使用故事板
-
.H
#import <UIKit/UIKit.h> @interface ViewController : UIViewController { NSObject *anObject; NSObject *anotherObject; } -(void) makeObjects; @end
-
在ViewController.m添加
-(void) makeObjects{ anObject = [[NSObject alloc] init]; anotherObject = [[NSObject alloc] init]; int a = 1; }
-
在AppDelegate.m添加一行
- (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; }
- 在ViewController.m
,在
anObject = [[NSObject alloc] init];
运行
- 步骤在断点
- 设置断点anObject = 0x00000000,另一个对象被设置!
答
您使用的是LLDB调试器吗?目前它在模拟器中不会给你正确的iVar值。切换回GDB,你会发现报告的正确值。我在这里发现了这种行为:UIViewController subclass can't assign instance variable。
是的,我报告了一个错误。我收到了苹果的回应,声明这是一个已知问题。
+0
谢谢Aaron,我在使用LLDB。 – 2012-03-14 10:54:50
+0
没问题@AlessandroCalciati,你介意接受我的回答吗?谢谢 :) – 2012-03-14 13:00:26
我喜欢你所做的格式。读起来非常有趣:) – deanWombourne 2012-03-13 17:23:56
Lol Rob,这是我在*上的第一篇文章。我没有格式化文本,只需复制并粘贴:) – 2012-03-14 10:58:06
有一个编辑按钮。 。 。 – deanWombourne 2012-03-14 12:13:29