我有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元素,因此成功設置了數據,但我不瞭解如何解決這個問題?
感謝,
傑克
旁註傑克 - 一些對象 - 純粹主義者會得到氣死我這麼說,但作爲一名新秀 - 採用簡單的符號,忘記舊的非點符號。 dView.name.text = foo比[[dView name] setText:foo]更容易閱讀。 – makdad 2011-05-30 01:25:20