2011-10-03 68 views
1

我嘗試在可可中做一個簡單的程序,一個帶有2個項目的NSTabVew,在第一個項目中我將內容設置爲一個字符串var,在第二個選項卡中顯示此值。我創建了兩個對象類(廈華,第二A),比我加入IB 2對象設置像廈華,第二ANSTabView之間傳遞值

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

看來,dato是零,這(根據你給我們的),可能是因爲事情沒有正確地在XIB上掛鉤。沒有更多的信息,我不能多說。

+0

在這裏,你可以下載的應用程序,我認爲你可以比我能寫的更好理解:D www.allmyapp.net/wp-content/Prova.zip – kikko088

+0

大概我明白問題....是行動,如果我用一些數據初始化我的類,例如nome = @「test」,我可以在Seconda類上看到我的var。我如何通過一個Action傳遞一個文本字段的變量? – kikko088