2013-02-25 45 views
0

我想繼承的UILabel所以二傳手的setText檢查空,以避免這種情況,如果所提供的參數是NSNULL: [NSNull isEqualToString:]:無法識別的選擇發送到實例Objective C的二傳手在超調用,而不是子類

代碼如下。我在調試器臺階的貫通,並沒有進入新的二傳手我把它叫做是:

[someSubClassLabel setText:someValueWhichMayBeNull]; 

其中someSubClassLabel是UILabelWithNULLHandler。

在.H

#import <UIKit/UIKit.h> 
@interface UILabelWithNULLHandler : UILabel 
- (void) setText:(NSString *) newText; 
@end 

定義在.M方法

- (void) setText:(NSString *) newText 
{ 
    if(![newText isKindOfClass:[NSNull class]]) 
    { 
     super.text = newText; 
    } 
    else 
    { 
     super.text = @""; 
    } 
} 

編輯: 我想我可以添加代碼來處理爲零,但暫時,我我正在處理從NSDictionary中提取的NSNUll。

+0

你確定是KindOfClass嗎?爲什麼不: if(newText){//做某事 ... – 2013-02-25 11:54:45

+3

而'someSubClassLabel'是'UILabelWithNULLHandler'的一個實例? – trojanfoe 2013-02-25 11:55:34

+1

你確定'someSubClassLabel'的類型是你的新'UILabelWithNULLHandler'嗎? – 2013-02-25 11:55:47

回答

0

@Hick Licks是對的。我的故事板中仍然有UILabel。需要在Custom Class中的Identity Inspector中設置新的類名。

相關問題