2009-08-26 35 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]; 
}