我有大量的UIImageVIEws,所以我需要知道哪个更改发生了.
我该如何做?谢谢.
解决方法 这被称为键值观察.可以观察到任何符合键值编码的对象,包括具有属性的对象.阅读 this programming guide关于KVO如何工作以及如何使用它.这是一个简短的例子(免责声明:它可能无效)- (ID) init{ self = [super init]; if (!self) return nil; // imageVIEw is a UIImageVIEw [imageVIEw addobserver:self forKeyPath:@"image" options:NSkeyvalueObservingOptionNew | NSkeyvalueObservingOptionold context:NulL]; return self;}- (voID) observeValueForKeyPath:(Nsstring *)path ofObject:(ID) object change:(NSDictionary *) change context:(voID *)context{ // this method is used for all observations,so you need to make sure // you are responding to the right one. if (object == imageVIEw && [path isEqualToString:@"image"]) { UIImage *newImage = [change objectForKey:NSkeyvalueChangeNewKey]; UIImage *oldImage = [change objectForKey:NSkeyvalueChangeoldKey]; // oldImage is the image *before* the property changed // newImage is the image *after* the property changed }}总结
以上是内存溢出为你收集整理的iphone – 当我的UIImageView.image属性更改时,有没有办法得到通知?全部内容,希望文章能够帮你解决iphone – 当我的UIImageView.image属性更改时,有没有办法得到通知?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)