0

The following UIImageView is drawn on my ViewController's window only after I exit the
-(void)playOn:(UIViewController*) currentViewController method. Why is that? How can I make it so that I can draw on my ViewController from inside that method while that method is executing?

CellPainter.m

-(void)paintGoodCellonViewController:(UIViewController*)playingViewController
{
    int x = 32*(xAxis - 1);
    int y = 384 - (32* yAxis);

    UIImageView* myImageView = [[UIImageView alloc] initWithImage:goodCell];
    myImageView.frame = CGRectMake(x,y, 32, 32);
    [playingViewController.view addSubview:myImageView];
}

Game.m

-(void)playOn:(UIViewController*) currentViewController
{    
    [currentPainter paintGoodCellonViewController:currentViewController];

    while(!self.stopButtonPressed)
    {
        // code...
    }
}

MyViewController.m

- (IBAction)enterButtonPressed:(UIButton *)sender
{
    [currentGame performSelectorInBackground:@selector(playOn:) withObject:self];
}

- (IBAction)giveUpButtonPressed:(UIButton *)sender
{
    currentGame.stopButtonPressed = YES;

}
Norton Commander
  • 653
  • 1
  • 10
  • 21

1 Answers1

1

Use this code to force UIView redraw:

[myView setNeedsDisplay];
Adam
  • 26,549
  • 8
  • 62
  • 79
  • Do you mean I call `[myImageView setNeedsDisplay];` right after `[playingViewController.view addSubview:myImageView];` in the above setting, or right before that? – Norton Commander Aug 23 '12 at 15:42
  • Call it after you add the view to your UI. On the other side, you may want to read [this answer](http://stackoverflow.com/a/4775803/730701). – Adam Aug 23 '12 at 15:48