【问题标题】:Objective-c and Xcode strange behaviorObjective-c 和 Xcode 的奇怪行为
【发布时间】:2012-03-13 17:20:19
【问题描述】:

在 xcode 4.3.1 中,目标是 iPad 5.1 模拟器

  • 创建单视图应用
  • 使用 ARC,不要使用 Storyboard

  • 在 ViewController.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, anotherObject 已设置!

【问题讨论】:

  • 我喜欢你对格式所做的工作。读起来很有趣:)
  • Lol Rob,这是我在 Stackoverflow 上的第一篇文章。我根本没有格式化文本,只需复制粘贴即可:)

标签: objective-c xcode


【解决方案1】:

您使用的是 LLDB 调试器吗?目前,它没有在模拟器中为您提供 iVar 的正确值。切换回 GDB,您会发现报告的正确值。我在这里发现了这种行为:UIViewController subclass can't assign instance variable

是的,我报告了一个错误。我收到了 Apple 的回复,称这是一个已知问题。

【讨论】:

  • 谢谢 Aaron,我使用的是 LLDB。
  • 没问题@AlessandroCalciati,你介意接受我的回答吗?谢谢:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-08-05
  • 2010-11-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多