私のプロジェクトには、検索バーがあります。
検索バーのテキストが変更された場合、私は知る必要があります
したがって、次のように比較する2つの静的 NSMutableString を宣言します
static NSMutableString *latestKeyWord;
static NSMutableString *secondaryKeyWord;
- (void)viewDidLoad
{
[super viewDidLoad];
[testViewController setSecondaryKeyWord:SBar.text];
[testViewController setLatestKeyWord:SBar.text];
[testViewController changeKeyWord];
}
+(void)setSecondaryKeyWord:(NSMutableString*) text
{
if (!secondaryKeyWord) {
secondaryKeyWord = [NSMutableString stringWithCapacity:200];
}
[secondaryKeyWord setString:text];
}
+(void)setLatestKeyWord:(NSMutableString*)text
{
if (!latestKeyWord) {
latestKeyWord = [NSMutableString stringWithCapacity:200];
}
[latestKeyWord setString:secondaryKeyWord];
}
-(BOOL)changeKeyWord
{
if ( ! [latestKeyWord isEqualToString:secondaryKeyWord]) {
NSLog(@"changed");
return TRUE;
}else {
NSLog(@"not change");
return FALSE;
}
}
在庫があるだけで、理由がわかりません。