is almost a week that i can't fix a brain painful problem:
I have a UIViewController subclass named StreamingViewControllerCommon that implement this property:
@property (nonatomic, assign, readonly) BOOL isMusicStopped;
and of course i @synthesize it in the .m file
then i have 2 subclasses of this class: Listen_UIViewController
and LastNews_UIViewController
that modify (not calling self.isMusicStopped
but accessing directly to it) the var isMusicStopped
.
In another Class i have a NSMutableDictionary that contains 2 instance (1 for each class) of these two classes but when i try to do this:
if (streamingViews){
for(StreamingViewControllerCommon* aView in streamingViews){
BOOL stopped = aView.isMusicStopped;
NSLog(@"%@",stopped);
if(stopped){
[aView closeStream];
[streamingViews removeObjectForKey:[aView class]];
[aView release];
aView = nil;
}
}
}
i obtain this error:
2011-02-08 15:55:09.760 ProjectName[6182:307] +[LastNews_UIViewController isMusicStopped]: unrecognized selector sent to class 0x2143c
2011-02-08 15:55:09.768 ProjectName[6182:307] CoreAnimation: ignoring exception: +[LastNews_UIViewController isMusicStopped]: unrecognized selector sent to class 0x2143c
But the weird thing is that in the StreamingViewControllerCommon implement also these methods:
-(void) destroyStreamer{
}
-(void) closeStream{
[self destroyStreamer];
}
and when i do:
NSMutableArray* keys = [[NSMutableArray alloc] initWithArray:[streamingViews allKeys]];
[keys removeObject:[thisView class]];
NSMutableArray *tmp = [[NSMutableArray alloc] initWithArray:[streamingViews objectsForKeys:keys notFoundMarker:@"404"]];
if (tmp){
for (StreamingViewControllerCommon* vc in tmp)
[vc closeStream];
[tmp release];
}
[streamingViews removeObjectsForKeys:keys];
i am not getting any error and the subcla开发者_Go百科sse's overridden closeStream methods are right called.
What am i doing wrong?
Best Regards, Antonio
EDIT: As I wrote in the comment: Changing this:
if (streamingViews){
for(StreamingViewControllerCommon* aView in streamingViews){
BOOL stopped = aView.isMusicStopped;
NSLog(@"%@",stopped);
if(stopped){
[aView closeStream];
[streamingViews removeObjectForKey:[aView class]];
[aView release];
aView = nil;
}
}
}
in this:
if (streamingViews){
for (id aViewClass in streamingViews){
StreamingViewControllerCommon* aView = [[streamingViews objectForKey:aViewClass] retain];
//NSLog(@"%@",aView.isMusicStopped);
if(aView.isMusicStopped){
[aView closeStream];
[streamingViews removeObjectForKey:aViewClass];
[aView release];
aView = nil;
}
}
}
Did the trick :P The for each cycle of a NSDictionary returns its keys not the objects and, since i was using the Class of objects as key i was obtaining that weird exception
For whatever reason, it looks like streamingViews
contains not an instance of LastNews_UIViewController, but the class itself. That's what the plus sign in +[LastNews_UIViewController isMusicStopped]
signifies.
精彩评论