2013年2月8日金曜日

AlertViewを自動で閉じる

AlertViewにボタンを表示せずに、メッセージを表示して一定時間後に自動的に閉じる。


-(void)okOrder:(UIButton*)btn
{
    UIAlertView *alt = [[UIAlertView alloc]initWithTitle:@"" message:@"注文を受け付けました" delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];
    //Timer 設定
    [NSTimer scheduledTimerWithTimeInterval:2.0f target:self selector:@selector(performDismiss:) userInfo:alt repeats:NO];

    [alt show];
}

//Timer終了でアラートを閉じる
-(void)performDismiss:(NSTimer*)timer
{
    UIAlertView *alt = [timer userInfo];
    [alt dismissWithClickedButtonIndex:0 animated:NO];
}

0 件のコメント:

コメントを投稿