下面的代码将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..");
}}
但是,无论字符串是什么,它们永远不会相等。代码片段
[CommandBox setStringValue:@""];应该不会影响任何事情,因为NSString是在实际框被清除之前设置的。
发布于 2011-05-21 01:30:57
问题是,当第二种方法不知道MyLoggerCommand是什么时,你却在比较它。尝试以下代码:
-(IBAction)SendAction:(id)sender {
NSString *myLoggerCommand = [CommandBox stringValue];
[[[MyLogger textStorage] mutableString] appendString: myLoggerCommand];
[self General_Combinations:myLoggerCommand];
[CommandBox setStringValue:@""];
}
-(void)General_Combinations:(NSString *)aString {
NSLog(@"General Combinations called..");
if([aString isEqualToString:@"this"])
{
NSLog(@"Matched..");
}
}https://stackoverflow.com/questions/6075524
复制相似问题