以下內容將NSString設置爲文本字段的StringValue。然後,字符串在General_combinations字符串比較
- (IBAction)SendAction:(id)sender
{
NSString *MyLoggerCommand = [CommandBox stringValue];
[CommandBox setStringValue:@""];
[[[MyLogger textStorage] mutableString] appendString: MyLoggerCommand];
[self General_Combinations];
}
- (void)General_Combinations
{
NSLog(@"General Combinations called..");
if([MyLoggerCommand isEqualToString:@"this"])
{
NSLog(@"Matched..");
}
}
然而相比,無論字符串是什麼,他們從來都不相等。 的片斷,因爲的NSString首先設置被清除的實際禁區前
[CommandBox setStringValue:@""];
應該不會有什麼影響。
它實際上,請參閱我的回答 – arclight 2011-05-20 17:30:21
此代碼沒有意義。你在'SendAction:'中聲明瞭一個局部變量,然後在另一個'General_Combinations'方法中引用該變量,在那裏它將不可用。這段代碼應該在運行時崩潰......這裏是否有一段代碼會使這項工作成爲現實? – 2011-05-20 17:37:45
是的,我宣佈NSString在頂層。我很愚蠢,忘記通過函數傳遞變量。 – evdude100 2011-05-20 17:47:40