【发布时间】: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