2011-05-29 24 views
1

我有UITableViewCell,點擊時會顯示從.xib文件加載的UIView。當我點擊單元格時,視圖成功顯示,但是我想在視圖元素中顯示的數據不會顯示。Rookie Obj-C問題 - UITableViewCell選擇在UIView子視圖中顯示沒有數據

代碼:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
// Navigation logic 
NSLog(@"didSelectRowAtIndexPath"); 

//Initialize a UIView that contains all the elements required to display the data 
EventDescriptionView *dView = [[EventDescriptionView alloc] init]; 
//Set the data in the elements to the data contained in the xml 
//Set up the cell 
int storyIndex = indexPath.row; 
[[dView name] setText:[[stories objectAtIndex: storyIndex] objectForKey: @"title"]]; 
[[dView date] setText:[[stories objectAtIndex: storyIndex] objectForKey: @"date"]]; 
NSLog(@"Index: %d", storyIndex); 
[[dView image] setImage:[images objectAtIndex:storyIndex]]; 
//Display the UIView 
[UIView beginAnimations:nil context:nil]; 

[UIView setAnimationDuration:0.5]; 

[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES]; 

[self.view addSubview:dView.view]; 

[UIView commitAnimations]; 

}

我可以看到行:

[[dView name] setText:[[stories objectAtIndex: storyIndex] objectForKey: @"title"]]; 
[[dView date] setText:[[stories objectAtIndex: storyIndex] objectForKey: @"date"]]; 
NSLog(@"Index: %d", storyIndex); 
[[dView image] setImage:[images objectAtIndex:storyIndex]]; 

沒有認可的DVIEW元素,因此成功設置了數據,但我不瞭解如何解決這個問題?

感謝,

傑克

+0

旁註傑克 - 一些對象 - 純粹主義者會得到氣死我這麼說,但作爲一名新秀 - 採用簡單的符號,忘記舊的非點符號。 dView.name.text = foo比[[dView name] setText:foo]更容易閱讀。 – makdad 2011-05-30 01:25:20

回答

2

的問題似乎是這條線。

int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1]; 

這似乎陌生,因爲它們映射到rowssections一個UITableView對象。因爲我期待stories映射到當前行,我覺得你的storyIndex應該是 -

int storyIndex = indexPath.row; 
+0

啊,是的,我明白你的意思了。不過,我改變了它,仍然得到了相同的結果。 – 2011-05-29 22:56:18

+0

這是在'tableView:didSelectRowAtIndexPath:',對嗎? – 2011-05-29 22:59:31

+0

嘗試記錄值以確保它們是正確的。 – 2011-05-29 23:03:21