2012-06-27 203 views
7

我已經完成了一百萬個UITables - 帶有字幕,圖像,背景,顏色,文本樣式 - 您的名字。突然間,我在這張桌子上轟然倒塌,特別是在調用單元格圖像的線上。 下面的代碼:UITableView圖像導致崩潰

// Configure the cell: 
cell.textLabel.font = [UIFont fontWithName:@"Franklin Gothic Book" size:18]; 
cell.textLabel.text = [leadershipMenu objectAtIndex:indexPath.row]; 
cell.detailTextLabel.text = [leadershipSubtitlesMenu objectAtIndex:indexPath.row]; 

// And here's the statement that causes the crash: 
cell.imageView.image = [leadershipPhotosMenu objectAtIndex:indexPath.row]; 

現在,我得到的錯誤是這樣的:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', 
reason: '-[__NSCFConstantString _isResizable]: unrecognized selector sent to instance 0xcacbc' 

我知道肯定導致崩潰的說法是

cell.imageView.image = ... 

原因,儘快正如我評論它一切正常。

我從來沒有在我的生活中看到的

-[__NSCFConstantString _isResizable]: 

錯誤。 我已經使用它,但發現它很少。

非常奇特。

誰在那裏得到任何線索?

+0

什麼是leadershipPhotosMenu?它是一組圖像嗎? – Vaquita

+0

你是如何在「leadershipPhotosMenu」數組中存儲圖像的?我可以看看它是什麼嗎? –

+0

當然,這裏的代碼是:'leadershipPhotosMenu = [[NSMutableArray alloc] initWithObjects:@「JohnQ.jpg」,@「BillZ.png」,nil];'那些圖像在我的項目中 - 意味着它們在Xcode中,包的一部分。 – sirab333

回答

12

。保存圖像的方式是導致問題的原因。

試試這個..

leadershipPhotosMenu = [[NSMutableArray alloc] initWithObjects:[UIImage imageNamed:@"JohnQ.jpg"], [UIImage imageNamed:@"BillZ.png"], nil]; 

上面的代碼將圖像存儲在您的mutableArray,這將工作,但我建議不要將圖像存儲在陣列中。

還可以幫助解決問題沒有你的陣列等中的代碼存儲你的圖像上面通過執行:

cell.imageView.image = [UIImage imageNamed:(NSString*)[leadershipPhotosMenu objectAtIndex:indexPath.row]]; 

此錯誤消息意味着您leadershipPhotosMenu內的對象不是圖像,但串

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', 
reason: '-[__NSCFConstantString _isResizable]: unrecognized selector sent to instance 0xcacbc' 
+0

耶穌 - 總腦屁。顯然,盯着屏幕的方式連續太多小時。在這個項目中,我有40張桌子和圖片,我看不到這個簡單的錯誤盯着我的臉。顯然時間到了麻袋:-)感謝男孩們! (對不起) – sirab333

+0

非常歡迎:) – janusbalatbat

1

這樣做:在您的評論中提到

cell.imageView.image = [UIImage imageNamed:[leadershipPhotosMenu objectAtIndex:indexPath.row]]; 
+0

正確,這是您可能遵循的另一種選擇。 – Tarun

1

您正在存儲圖像廣告的名稱而不是圖像。不過imageView具有UIImage作爲其屬性,而不是圖像名稱。所以讓下面的改變。

cell.imageView.image = [UIImage imageNamed:[leadershipPhotosMenu objectAtIndex:indexPath.row]];