1

我尝试在可可中做一个简单的程序,一个有 2 个项目的 NSTabVew,在第一个项目中我将内容设置为字符串 var,在第二个选项卡中显示这个值。我创建了两个对象类(Prima 和 Seconda),而不是在 IB 设置中添加 2 个对象,例如 Prima 和 Seconda

Prima.m

- (IBAction) salva:(id) sender{  
    nome = [field stringValue];
    NSLog(@"%@",nome);
}

- (IBAction) visualizza:(id) sender{
    NSString *dato;
    Prima *prima = [[Prima alloc] init];
    dato = prima.nome;
    [label setStringValue:dato];
}

当我运行程序时,我收到此错误:

2011-10-03 11:42:43.511 Prova[44622:707] *** Assertion failure in -[NSTextFieldCell _objectValue:forString:errorDescription:], /SourceCache/AppKit/AppKit-1138/AppKit.subproj/NSCell.m:1564
2011-10-03 11:42:43.511 Prova[44622:707] Invalid parameter not satisfying: aString != nil
2011-10-03 11:42:43.513 Prova[44622:707] (
    0   CoreFoundation                      0x00007fff8d497986 __exceptionPreprocess + 198
    1   libobjc.A.dylib                     0x00007fff90ed9d5e objc_exception_throw + 43
    2   CoreFoundation                      0x00007fff8d4977ba +[NSException raise:format:arguments:] + 106
    3   Foundation                          0x00007fff8cce914f -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 169
    4   AppKit                              0x00007fff88957685 -[NSCell _objectValue:forString:errorDescription:] + 160
    5   AppKit                              0x00007fff889575df -[NSCell _objectValue:forString:] + 19
    6   AppKit                              0x00007fff88957545 -[NSCell setStringValue:] + 41
    7   AppKit                              0x00007fff88a58039 -[NSControl setStringValue:] + 115
    8   Prova                               0x0000000100001365 -[Seconda visualizza:] + 133
    9   CoreFoundation                      0x00007fff8d48711d -[NSObject performSelector:withObject:] + 61
    10  AppKit                              0x00007fff88a3f852 -[NSApplication sendAction:to:from:] + 139
    11  AppKit                              0x00007fff88a3f784 -[NSControl sendAction:to:] + 88
    12  AppKit                              0x00007fff88a3f6af -[NSCell _sendActionFrom:] + 137
    13  AppKit                              0x00007fff88a3eb7a -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 2014
    14  AppKit                              0x00007fff88abe57c -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 489
    15  AppKit                              0x00007fff88a3d786 -[NSControl mouseDown:] + 786
    16  AppKit                              0x00007fff88a0866e -[NSWindow sendEvent:] + 6280
    17  AppKit                              0x00007fff889a0f19 -[NSApplication sendEvent:] + 5665
    18  AppKit                              0x00007fff8893742b -[NSApplication run] + 548
    19  AppKit                              0x00007fff88bb552a NSApplicationMain + 867
    20  Prova                               0x0000000100000f92 main + 34
    21  Prova                               0x0000000100000f64 start + 52
    22  ???                                 0x0000000000000001 0x0 + 1
)

你的错误在哪里?

4

1 回答 1

1

dato 似乎是 nil,这(根据您给我们的内容)可能是因为 XIB 中没有正确连接。没有更多信息,我不能说更多。

于 2011-10-03T10:14:50.307 回答