我正在尝试制作一个 TableViewController .. 我使用 youtube 课程中的代码让它工作:“Cocoa Programming L13-14” 但是当我尝试更改它以便默认值不是硬编码时......但是而不是 Interface Builder 中控件的值,我得到 (null) 全面。这是代码:
#import <Foundation/Foundation.h>
@interface Person : NSObject {
IBOutlet NSPathControl* pcSource;
IBOutlet NSPathControl* pcDestination;
IBOutlet NSTextField* tfBackupAmount;
NSURL* urlSource;
NSURL* urlDestination;
NSString* strBackupAmount;
//Old--
//NSString* name;
//int age;
}
@property NSURL* urlSource;
@property NSURL* urlDestination;
@property NSString* strBackupAmount;
//Old--
//@property (copy) NSString* name;
//@property int age;
@end
和
#import "Person.h"
@implementation Person
@synthesize urlSource;
@synthesize urlDestination;
@synthesize strBackupAmount;
//Old--
//@synthesize name;
//@synthesize age;
- (id)init {
self = [super init];
if (self) {
urlSource = [pcSource URL];
urlDestination = [pcDestination URL];
strBackupAmount = [tfBackupAmount stringValue];
NSLog(@"%@\n%@\n%@",urlSource,urlDestination,strBackupAmount);
//Old--
//name = @"Yoda";
//age = 900;
//NSLog(@"%@: %i", name, age);
}
return self;
}
@end
一切都评论了 //Old-- 工作正常,并且与 TableViewController 交互良好。所以我假设所有这些仍然可以正常工作。3 个控件(2 个 NSPathControl 和 1 个 NSTextField)被链接到一个 Object 类:Interface Builder 中的 Person,这些控件被链接起来。为什么我得到以下输出:
(null)
(null)
(null)
? 当我到达 NSLog(); 线?我哪里错了?谢谢!