0
以下UIImageView
僅在我退出
-(void)playOn:(UIViewController*) currentViewController
方法後在我的ViewController窗口繪製。這是爲什麼?我怎樣才能讓我可以在裏面使用我的ViewController裏面的那個方法而那個方法正在執行?爲什麼我的UIImageView對象不是實時繪製的?
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;
}
你的意思是我在'[playingViewController.view addSubview:myImageView]'之後調用'[myImageView setNeedsDisplay];''在上述設置中,還是在此之前? –
將視圖添加到用戶界面後調用它。另一方面,你可能想閱讀[這個答案](http://stackoverflow.com/a/4775803/730701)。 – Adam