这是iphone开发的新手,我似乎不明白为什么会发生这种情况。我很确定这与boardView是nill创建新视图的事实有一定关系。但我正在将图像应用于新形成的imageView,所以我不确定发生了什么。就像我说的,一切都好用。我得到我的项目列表点击一个项目,它会带着正确的图像进入下一页(除了第一次)。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSInteger row = [indexPath row];
if(self.boardView == nil){
BoardView *aboardView = [[BoardView alloc]initWithNibName:@"BoardView" bundle:nil];
self.boardView = aboardView;
[aboardView release];
}
NSString *filePath = [[NSBundle mainBundle] pathForResource:[snowBoardArray objectAtIndex:row] ofType:@"png"];
UIImage *theImage = [[UIImage alloc] initWithContentsOfFile:filePath];
self.boardView.imageView.image = theImage;
[theImage release];
[self.navigationController pushViewController:self.boardView animated:YES];
}
boardView几乎是一个空白的UIViewController,除了添加了imageView
您可以添加这一行,尽管这有点麻烦。您只需要访问viewcontroller的视图,就可以创建它。您可以通过修改任何视图属性来避免编译器发出警告。我建议做以下事情。
self.boardView.view.hidden = NO;
我遇到了这个问题,您所要做的就是调用要创建的视图。即使像self.boardView.view;
这样的简单行就足够了,为了避免编译器警告,请更改隐藏属性。
尽管您创建了BoardView控制器,但其视图层次结构可能尚未创建——它可能仅在显示控制器时启动。因此,当你第一次尝试显示它时,它的所有UI元素仍然等于零,并且你的调用
self.boardView.imageView.image = theImage;
什么也不做。
作为一种可能的解决方案,将UIImage作为BoardView控制器的一个单独属性,在didSelectRowAtIndexPath方法中设置它,并在您确定创建了imageView时将图像分配给您的imageView,例如在控制器的viewWillAppear:
方法