0

ユーザーの操作がない状態でしばらくしたら、アプリからログアウトしたいと考えています。これを行う方法の例を見つけました。非アクティブ タイマーが切れたら、「 XX 秒でログアウトする」というポップアップを表示したいと思います。ここで、秒数が更新されます。つまり、60、59、58 が減っていき、0 に達します。ユーザーをログアウトします(ポップアップには、実装が簡単だと思う「ログアウトのキャンセル」ボタンもあります。)そのようなポップアップを作成する簡単な方法があるかどうかを調べようとしています-私には好きなようですかなり一般的なアイデアですが、これまでのところ何も見つかりませんでした。

4

2 に答える 2

3

プライベート インターフェイスに 2 つのプロパティを追加します。

@interface MyViewController ()
@property(nonatomic, strong) UIAlertView *logoutAlertView;
@property(nonatomic) NSUInteger logoutTimeRemaining;
@end

アラートを表示するときは、次のようにします。

self.logoutAlertView = [[UIAlertView alloc] initWithTitle:@"Title"
                                                  message:@"Logging out in 60 seconds"
                                                 delegate:self
                                        cancelButtonTitle:@"Dismiss"
                                        otherButtonTitles:nil];
[self.logoutAlertView show];

self.logoutTimeRemaining = 60;

[NSTimer scheduledTimerWithTimeInterval:1
                                 target:self
                               selector:@selector(updateAlert:)
                               userInfo:nil
                                repeats:YES];

メソッドupdateAlert:は次のようになります。

- (void)updateAlert:(NSTimer *)timer {
    self.logoutTimeRemaining--;
    self.logoutAlertView.message = [NSString stringWithFormat:@"Logging out in %d seconds", self.logoutTimeRemaining];

    if (self.logoutTimeRemaining == 0) {
        // actually log out
        [timer invalidate];
    }
}
于 2013-03-13T16:46:06.110 に答える
2

この場合、カスタムを実装し、値を変更するタイマーで をUIAlertView追加する ことをお勧めします。UILabel

このスレッドの私の回答に従ってください。あなたのケースUILabelの代わりに追加UIButtonしてください。

于 2013-03-13T16:17:21.960 に答える