0

我在我的函数中创建 UIAlertView ,问题是它在函数运行时显示了很多时间,我如何创建一个if语句来只显示一次,就像如果UIAlertView显示不再显示一样。在目标-C

- (void)showAlert {

    _myAlertView = nil;
    _myAlertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Call_On_Hold",nil)
                                              message:NSLocalizedString(@"Please_Wait",nil)
                                             delegate:self
                                    cancelButtonTitle:NSLocalizedString(@"Close_call",nil)
                                    otherButtonTitles:nil, nil];
    _myAlertView.tag = myAlertViewsTag;

    [_myAlertView show];

}

这是我的 UIAlertView 连续出现而不是一次出现的功能。

- (void) trafficTimerRun:(NSTimer*)theTimer
{
    ++ trafficTimerTicks;

    pjmedia_rtcp_stat stat;

    if (!get_stream_info([call_id intValue], &stat)) {
        return;
    }

    LogDebug(TAG_SIP, @"Got %d bytes on stream 0 (previous: %d)", stat.rx.bytes, prev_bytes);

    if (stat.rx.bytes == prev_bytes) {
        if (trafficTimerTicks >= 10) {

            // Steve-note: Here we need to show a pop-up message when the call in on hold when the trafficTimerTicks run.
            [self showAlert];

            LogError(TAG_SIP, @"No traffic received, hanging up");

            // [theTimer invalidate];
            // broken = YES; Steve note: The call shouldnt broke.
            // [self hangup]; Steve note: The call shouldnt hangup.
        }
    }
}

提前致谢。

4

1 回答 1

0

使用布尔值:

bool alertIsShowing = false;

并在您的更新方法中放置如下内容:

if (trafficTicks > 10){
 if (!alertIsShowing){
     alertIsShowing = true;
     [self showAlert];
   }
}

然后当您的警报被解除时,重置您的布尔值:

alertIsShowing = false;
于 2017-05-12T10:05:22.197 回答