我在我的函数中创建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.
}
}
}
先谢谢。
答案 0 :(得分:0)
使用布尔值:
bool alertIsShowing = false;
并在您的更新方法中添加如下内容:
if (trafficTicks > 10){
if (!alertIsShowing){
alertIsShowing = true;
[self showAlert];
}
}
然后当你的警报被解雇时,重置你的布尔值:
alertIsShowing = false;