我有一个名为DictionaryConsole
的UITextView。每隔0.05秒,基于以下switch语句将文本设置为它:
switch ((DictionaryLine*100)/NumberofWordsTilEnd) {
case 10:
NewLine = [NSString stringWithFormat: @"Attack is Now 10 Percent Complete"];
NewLine2 = [NewLine stringByAppendingString:@"\n"];
DictionaryConsole.text = [NewLine2 stringByAppendingString:DictionaryConsole.text];
break;
case 25:
NewLine = [NSString stringWithFormat: @"Attack is Now 25 Percent Complete"];
NewLine2 = [NewLine stringByAppendingString:@"\n"];
DictionaryConsole.text = [NewLine2 stringByAppendingString:DictionaryConsole.text];
break;
case 50:
NewLine = [NSString stringWithFormat: @"Attack is Now 50 Percent Complete"];
NewLine2 = [NewLine stringByAppendingString:@"\n"];
DictionaryConsole.text = [NewLine2 stringByAppendingString:DictionaryConsole.text];
break;
case 75:
NewLine = [NSString stringWithFormat: @"Attack is Now 75 Percent Complete"];
NewLine2 = [NewLine stringByAppendingString:@"\n"];
DictionaryConsole.text = [NewLine2 stringByAppendingString:DictionaryConsole.text];
break;
case 80:
NewLine = [NSString stringWithFormat: @"Attack is Now 80 Percent Complete"];
NewLine2 = [NewLine stringByAppendingString:@"\n"];
DictionaryConsole.text = [NewLine2 stringByAppendingString:DictionaryConsole.text];
break;
case 90:
NewLine = [NSString stringWithFormat: @"Attack is Now 90 Percent Complete"];
NewLine2 = [NewLine stringByAppendingString:@"\n"];
DictionaryConsole.text = [NewLine2 stringByAppendingString:DictionaryConsole.text];
break;
case 95:
NewLine = [NSString stringWithFormat: @"Attack is Now 95 Percent Complete"];
NewLine2 = [NewLine stringByAppendingString:@"\n"];
DictionaryConsole.text = [NewLine2 stringByAppendingString:DictionaryConsole.text];
case 98:
NewLine = [NSString stringWithFormat: @"Attack is Now 98 Percent Complete"];
NewLine2 = [NewLine stringByAppendingString:@"\n"];
DictionaryConsole.text = [NewLine2 stringByAppendingString:DictionaryConsole.text];
break;
default:
break;
}
这是NSTimer
:
Dictionary = [NSTimer scheduledTimerWithTimeInterval:0.05
target:self
selector:@selector(DictionaryAttack)
userInfo:nil
repeats:YES];
每次调用-(void)DictionaryAttack
时,都会执行该switch语句。 Dictionary Line
是一个在-(void)DictionaryAttack
中增加1的int。字符串可以毫无问题地转到DictionaryConsole
(UITextView
)。但是我的问题是NewLine
字符串中的33个是"打印"到文本视图。但是,我只想要一个字符串"打印"。我做错了什么?
答案 0 :(得分:1)
你试图划分整数。结果将是截断数字,可能多次适合您的开关案例。例如:10.0
将截断为10
,10.1
也会截断,因此您的切换case 10
代码将多次执行。