开发者

next view displays wrong image the first time

Very new to iphone development and i cant seem to figure out why this is happening. im pretty sure it has somthing todo with the fact that with boardView is nill it creates a new one. but im applying the image to the newly formed imageView so im not sure whats going on. like i said, everything works. i get my list of items click on an item and it goes to the next page with the correct image (EXCEPT the very first time).

- (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 *filePa开发者_StackOverflow社区th = [[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 is almost a blank UIViewController with the exception of having the added imageView


You can add this line although its bit of a hack. You have to just access viewcontroller's view so that its created. You can avoid compiler warning by modifying any of the views property. I would suggest to do the following.

self.boardView.view.hidden = NO;

I had this issue and all you have to do is call the view to be created. Even though a simple line like self.boardView.view; should suffice, to avoid the compiler warning change the hidden property.


Although you created BoardView controller its view hierarchy may not be created yet - it may be initiated only when controller is being displayed. So when you try to show it for the first time all its UI elements are still equal to nil and your call

self.boardView.imageView.image = theImage;

does nothing.

As a possible solution make UIImage as a separate property of your BoardView controller, set it in didSelectRowAtIndexPath method and assign image to your imageView when you're sure that imageView is created, e.g. in controller's viewWillAppear: method

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜