警报视图显示多次而不是一次
The Alert View shows many time not one time
我在我的函数中创建了 UIAlertView,问题是它在函数运行时显示了很多时间,我如何创建一个 if
语句只显示一次,就像 UIAlertView
显示一样不再显示。
- (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.
}
}
}
使用布尔值:
bool alertIsShowing = false;
并在您的更新方法中输入如下内容:
if (trafficTicks > 10){
if (!alertIsShowing){
alertIsShowing = true;
[self showAlert];
}
}
然后当您的警报被解除时,重置您的布尔值:
alertIsShowing = false;
我在我的函数中创建了 UIAlertView,问题是它在函数运行时显示了很多时间,我如何创建一个 if
语句只显示一次,就像 UIAlertView
显示一样不再显示。
- (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.
}
}
}
使用布尔值:
bool alertIsShowing = false;
并在您的更新方法中输入如下内容:
if (trafficTicks > 10){
if (!alertIsShowing){
alertIsShowing = true;
[self showAlert];
}
}
然后当您的警报被解除时,重置您的布尔值:
alertIsShowing = false;