2009-08-26 40 views

回答

2

將文本字段的值綁定到某個對象的屬性,並確保在Interface Builder中檢查「連續更新」框。對於這個例子,該屬性將被稱爲theText。然後,使用的鍵值路徑說containsLetterA綁定按鈕的啓用狀態,然後在你的對象把方法

- (BOOL) containsLetterA 
{ 
    NSRange rangeOfLetterA = [[self theText] rangeOfString:@"A"]; 
    return rangeOfLetterA.location != NSNotFound; 
} 

隨後,同樣在你的對象,添加類方法:

+ (NSSet *) keyPathsForValuesAffectingValueForContainsLetterA 
{ 
    return [NSSet setWithObjects:@"theText", nil]; 
}