Comments (4)
I am afraid this is how UITextField
works now. This behavior was changed in some version of iOS, because it definitely was working that way.
from block-kvo.
I changed the example in README, that was using UITextFiel.text
observation.
from block-kvo.
Found a workaround, just set the viewController
as textField
's delegate and add the following method.
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
textField.text = [textField.text stringByReplacingCharactersInRange:range withString:string];
return NO;
}
from block-kvo.
This is also an option, subclass UITextField
and add observableText
property.
@interface MTKTextField : UITextField
@property (nonatomic, copy) NSString *observableText;
@end
@implementation MTKTextField
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self addTarget:sefl action:@selector(updateText) forControlEvents:UIControlEventEditingChanged];
}
return self;
}
- (void)updateText {
// Calling the setter should invoke observation methods.
self.observableText = self.text;
}
- (NSString *)observableText {
// Just forwarding to `text` property.
return self.text;
}
- (void)setObservableText:(NSString *)observableText {
// Just forwarding to `text` property.
self.text = observableText;
}
@end
Then just use this class instead fo standard UITextField
.
Be careful, because assigning self.text
to self.text
will not invoke observation blocks. That's a feature of this library. It's usualy useful, but sometimes causes troubles like this.
from block-kvo.
Related Issues (20)
- Readme.md Is it necessary to remove the observer (like with regular KVO) or not? HOT 8
- Support removing observer for specified keypath
- Not compiling with Xcode 6.3, Swift 1.2 HOT 9
- Compile error when included in .mm file HOT 3
- Can't compile 'objc_msgSend has too many arguments' HOT 9
- Block-KVO logic should follow the same approach as original KVO HOT 1
- Macro MTKObservePropertySelf can not use with stringWithFormat in the block HOT 2
- MTKObserver should removeObserver in dealloc HOT 5
- can you delete "block(self, nil);" HOT 1
- Update deployment_target for cocoa pods HOT 1
- Expose change dictionary for observing collections HOT 2
- Obscure retain issue in -removeAllObservationsOfObject: HOT 10
- Registering change observer without calling block with initial value HOT 3
- Initial value detection HOT 4
- Two-way binding causing infinite loop HOT 2
- Too Many Arguments to Function Call HOT 3
- Update cocoapods version HOT 1
- Want my stuff HOT 2
- PodSpec Version HOT 1
- worth mentioning the use of @keypath in the example
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from block-kvo.