iOS: как удалить оверлей из его подпредставления? - PullRequest
0 голосов
/ 23 апреля 2011

У меня есть кнопка, которая делает наложение с меткой и кнопкой X на нем:

- (IBAction)taptaxi:(id)sender {
    UIView *overlay = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
    overlay.backgroundColor = [UIColor colorWithWhite:0 alpha:.7];
    UILabel *waiting = [[[UILabel alloc] initWithFrame:CGRectMake(50, 210, 250, 30)] autorelease];
    waiting.text = @"Waiting for cab response...";
    waiting.textColor = [UIColor whiteColor];
    waiting.backgroundColor = [UIColor clearColor];   
    waiting.font = [UIFont systemFontOfSize:14];

    UIButton *stoprequest = [[UIButton alloc] initWithFrame:CGRectMake(225, 219, 13, 13)];
    UIImage *srbackground = [[UIImage imageNamed:@"iks.png"] stretchableImageWithLeftCapWidth:0 topCapHeight:0];
    [stoprequest setBackgroundImage:srbackground forState:UIControlStateNormal];
    [stoprequest addTarget: self action: @selector(stopRequestMethod:) forControlEvents: UIControlEventTouchUpInside];

    [self.view.window addSubview:overlay];
    [overlay addSubview:waiting];
    [overlay addSubview:stoprequest];


}

- (void)stopRequestMethod: (id)sender
{
}

Вопрос , как скрыть / удалить наложение с меткой и кнопкой, когда я нажимаю на Xbutoon (stopRequestMethod)?

1 Ответ

2 голосов
/ 23 апреля 2011

Дайте вашему наложению тег:

overlay.tag = 42;

Затем в вашем методе, который вызывается при нажатии кнопки X:

UIView *overlay = [self.view.window viewWithTag:42];
[overlay removeFromSuperview];
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...