2011-02-08 21 views
1

幾乎是一個星期,我不能修復大腦痛苦的問題:目標C:無法識別的選擇發送到的UIViewController子類子類

我有一個名爲StreamingViewControllerCommon一個UIViewController子類實現這個屬性:

@property (nonatomic, assign, readonly) BOOL isMusicStopped; 

當然我@synthesize它在.m文件

然後我有2個亞類這個類的:Listen_UIViewControllerLastNews_UIViewController修飾(不調用self.isMusicStopped但accessin g直接給它)var isMusicStopped

在另一個I類具有這兩個類的包含2實例(1爲每個類)一個的NSMutableDictionary但是當我嘗試這樣做:

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; 
      } 
     } 
    } 

我獲得這個錯誤:

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 

但奇怪的是,在StreamingViewControllerCommon還實現這些方法:

-(void) destroyStreamer{ 
} 

-(void) closeStream{ 
    [self destroyStreamer]; 
} 

,當我做:

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]; 

我沒有得到任何錯誤和subclasse的重載closeStream方法正確調用。

我在做什麼錯了?

最好的問候,安東尼奧

編輯:正如我在評論中寫道:更改此:

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; 
      } 
     } 
    } 

在此:

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; 
     } 
    } 
} 

的伎倆:P的每個週期的NSDictionary返回它的鍵不是對象,並且,因爲我使用的類的對象作爲鍵我得到那個奇怪的異常

+0

ok多麼愚蠢...... Thx對你的評論查克我明白,我從foreach循環得到的是鍵,而不是對象,因爲我使用類作爲鍵它返回了錯誤...改變週期:for(idViewView中的streamingViews){ \t \t \t StreamingViewControllerCommon * aView = [[streamingViews objectForKey:aViewClass] retain]; \t \t \t //NSLog(@"%@",aView.isMusicStopped); (aView。 \t \t \t if(aView。isMusicStopped){ \t \t \t \t [aView closeStream]; \t \t \t \t [streamingViews removeObjectForKey:aViewClass]; \t \t \t \t [aView release]; \t \t \t \t aView = nil; \t \t \t} \t \t} 奏效了:P – 2011-02-08 17:02:19

回答

2

無論出於何種原因,它看起來像streamingViews不包含LastNews_UIViewController的實例,而是包含類本身。這就是+[LastNews_UIViewController isMusicStopped]表示的加號。

+0

等等,爲什麼同樣的事情不會在其他方法中發生的呢?我的意思是爲什麼當我做[vc closeStream]時不會拋出異常? – 2011-02-08 15:55:19

相關問題