2012-05-09 19 views
0

我想定製我的tableView細胞的高度時,會拋出錯誤。我嘗試了幾個教程,但似乎沒有任何工作。 「有趣的事情」是錯誤消息總是相同的。下面是我使用ATM代碼:的TableView試圖實現dymanic細胞高度

#define PADDING 10.0f 
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath  *)indexPath 
{ 
NSString *text = [self.tabelle objectAtIndex:indexPath.row]; 
CGSize textSize = [text sizeWithFont:[UIFont systemFontOfSize:14.0f] constrainedToSize:CGSizeMake(self.tableView.frame.size.width - PADDING * 3, 1000.0f)]; 

return textSize.height + PADDING * 3; 

} 

這是錯誤消息我得到:

2012-05-09 20:01:55.553 APP[436:f803] -[APP sizeWithFont:constrainedToSize:]: unrecognized selector sent to instance 0x687f5f0 
2012-05-09 20:01:55.555 APP[436:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[APP sizeWithFont:constrainedToSize:]: unrecognized selector sent to instance 0x687f5f0' 
*** First throw call stack: 
(0x128e022 0x1846cd6 0x128fcbd 0x11f4ed0 0x11f4cb2 0x42c9 0x3ab688 0x3ad862 0x25b66d 0x25b167 0x2f4d 0x34e8 0x29638f 0x2965eb 0x2a6ff1 0x2a785f 0x2a79e1 0x3c55c2 0x20bd21 0x128fe42 0xea679 0xf4579 0x794f7 0x7b3f6 0x108160 0x1cbe84 0x1cc767 0x1db183 0x1dbc38 0x1cf634 0x2181ef5 0x1262195 0x11c6ff2 0x11c58da 0x11c4d84 0x11c4c9b 0x1cbc65 0x1cd626 0x24a5 0x1d35) 
terminate called throwing an exception 

我首先想到的是,它不喜歡我設置的字體大小在

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

標籤但是,這似乎並沒有這樣的情況

回答

2

你得到這個錯誤的原因是CA使用此:

[self.tabelle objectAtIndex:indexPath.row]; 

將返回在tabelle有自定義對象,而不是一個NSString,而你對它調用一個NSString方法。也許你的意思是使用根據您要基於其大小文本

[[self.tabelle objectAtIndex:indexPath.row] Name] 

[[self.tabelle objectAtIndex:indexPath.row] m_yolo] 

編輯以使用自定義對象TABELLE

+0

謝謝,但現在我得到另一個錯誤:***終止應用程序由於未捕獲的異常 'NSInvalidArgumentException',原因是:「 - [APP爲textLabel]:無法識別的選擇器發送到實例0x6a99400' – Blade

+0

您是否使用常規的UITableViewCell?你能複製你的整個cellForRowAtIndexPath方法嗎? –

+0

你確定,你在這裏。但現在有點錯誤,在顯示任何內容之前,我總是需要點擊「顯示下一個X條目」。不知道那裏出了什麼問題。 http://pastebin.com/ZGpEKEKB – Blade