2014-01-15 39 views
0

我有一個錯誤。iphone os 5 - 無法識別的選擇器發送到實例

UIImage *img = [[UIImage imageNamed:@"bg_message.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(47, 32, 47, 32) resizingMode:UIImageResizingModeStretch]; 


UIImage *img = [[UIImage imageNamed:@"bg_message.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(47, 32, 47, 32) resizingMode:UIImageResizingModeStretch]; 
UIImageView *imgView = [[UIImageView alloc] initWithFrame:frame]; 
[imgView setImage:img]; 
[imgView setTag:99999999]; 
[self.view addSubview:imgView]; 

而剛剛滿足OS 5,OS 6和7通過。

//This is the error message 

*終止應用程序由於未捕獲的異常 'NSInvalidArgumentException',原因: ' - [UIImage的resizableImageWithCapInsets:resizingMode:]:無法識別的選擇發送到實例0xd86c2c0'

我不不明白。 任何人都可以幫助我,請! 非常感謝!

回答

3

-[UIImage resizableImageWithCapInsets:resizingMode:]僅適用於或之後的iOS 6(參考:Link

如果你建立在新的Xcode這個API的應用程序,它會告訴你沒有警告或錯誤。但是當你在iOS 5設備上運行應用程序時,它會拋出無法識別的選擇器異常。很難捕捉到這樣的錯誤。所以最好的測試方法是在iOS 5模擬器/設備上運行。

這是一個很好的做法太查找文檔。蘋果很好地寫了文檔。你也可以通過閱讀來學習。

+0

閱讀文檔?你瘋了嗎,男人?!?當你可以讓別人爲你做這件事時,爲什麼要自己去做這件事! :/ –

1

與resizingMode的變體在iOS6的只添加。如果你想在ios5下運行,你必須檢查該方法是否可用。

+0

你能告訴我更多 – bachle26

+0

當然 - 只是把if語句來決定是否UIImage的支持方法 - 所以是這樣的:如果([UIImage的instancesRespondToSelector:@selector(resizableImageWithCapInsets:resizingMode :)]){執行並調整其大小}其他{做別的事情} – racraman

+0

非常感謝racrama! – bachle26

相關問題