Я объявил 4 изображения в ViewDidLoad в моем ViewController, а затем спрячу их с myImage1.hidden = YES;
.Есть ли способ изменить состояние UIImageView из App Delegate?
мне было интересно, если есть в любом случае отправки сообщения из App делегата (изнутри коммутатора Case) для ViewDidLoad
метода ViewController, который устанавливает UIImageView
для скрытых: myImage1.hidden = NO;
-(void)playIndex:(NSInteger)index
{
switch (index)
{
case 1:
[self playOne];
[// something here to tell the UIImageView .hidden = NO;]
break;
Я не уверен, что это возможно, но подумал, что кто-то может пролить свет на то, что я пытаюсь сделать. Я просто хочу, чтобы изображение стало видимым одновременно с case 1: [self playOne];
, когда оно вызвано.
Если этого не сделать, есть ли другой способ, который я мог бы попытаться достичь?
`- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
AppDelegate* app = [[UIApplication sharedApplication] delegate];
UIImage *redSquare = [UIImage imageNamed:@"red_square.png"];
UIImage *blueSquare = [UIImage imageNamed:@"blue_square.png"];
UIImage *greenSquare = [UIImage imageNamed:@"green_square.png"];
UIImage *yellowSquare = [UIImage imageNamed:@"yellow_square.png"];
UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(72, 117, 60, 60)];
UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:CGRectMake(188, 117, 60, 60)];
UIImageView *imageView3 = [[UIImageView alloc] initWithFrame:CGRectMake(72, 254, 60, 60)];
UIImageView *imageView4 = [[UIImageView alloc] initWithFrame:CGRectMake(188, 254, 60, 60)];
[self.view addSubview:imageView1];
[self.view addSubview:imageView2];
[self.view addSubview:imageView3];
[self.view addSubview:imageView4];
imageView1.animationImages = @[redSquare];
imageView2.animationImages = @[blueSquare];
imageView3.animationImages = @[greenSquare];
imageView4.animationImages = @[yellowSquare];
imageView1.animationDuration = 1;
imageView2.animationDuration = 1;
imageView3.animationDuration = 1;
imageView4.animationDuration = 1;
imageView1.hidden = YES;
imageView2.hidden = YES;
imageView3.hidden = YES;
imageView4.hidden = YES;
[imageView1 startAnimating];
[imageView2 startAnimating];
[imageView3 startAnimating];
[imageView4 startAnimating];
Заявление переключателя в приложение делегата: (в том числе ссылки ViewController)
-(void)playIndex:(NSInteger)index
{
ViewController* mainController = (ViewController*) self.window.rootViewController;
switch (index)
{
case 1: [self playOne]; [mainController imageView1Hidden]; break;
case 2: [self playTwo]; break;
case 3: [self playThree]; break;
case 4: [self playFour]; break;
}
}
Большое вам спасибо за помощь. Ссылка на страницу полезна, однако она не указала, куда положить MyViewController * mainController = (MyViewController *) self.window.rootViewController; 'Я полагаю, что он входит в мой' - (void) playIndex: (NSInteger) индекс {'? – hbondy
Конечно. Это одно место, куда он мог пойти. Он может идти везде, где вам нужна ссылка на ваш контроллер просмотра. – joelg
Хорошо, имеет смысл. Мне нужно «#import» ViewController.m «'? – hbondy