在NSTabView之间传递值

时间:2011-10-03 09:51:40

标签: xcode macos cocoa nstabview

我尝试在cocoa中执行一个简单的程序,一个带有2个项目的NSTabVew,在第一个项目中我将内容设置为字符串var,在第二个选项卡中我显示此值。我创建两个Object类(Prima和Seconda),比我在IB设置中添加2个对象,如Prima和Seconda

Prima.m

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

Seconda.m

- (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
)

你的错误在哪里?

1 个答案:

答案 0 :(得分:1)

似乎dato是零,这(基于你给我们的东西)可能是因为事情没有在XIB中连接起来。没有更多信息,我不能多说。