我目前正在使用Xcode的iOS应用程序,并且已经提出了用于计算有效位数的代码。它是用C++编写的,但我做了一些改变以使其起作用。每当我输入一个零值,它崩溃,其他任何工作都很好。iOS调试器在文本框中输入0.0时崩溃
我的代码如下:
- (IBAction)sigFigCount:(UITextField *)thetextfield
{
length = 0;
if (thetextfield == _textfield1)
{
if ([thetextfield.text length] > 0)//If TextField Has More Than 0 digits...
{
text1 = std::string([_textfield1.text UTF8String]);
while (text1.at(0) == '0' || text1.at(0) == '.')//Trim Leading Zeros...
{
text1 = text1.substr(1);
}
length = text1.length();
decimal = text1.find('.');
if (decimal >= 0 && decimal < text1.length())//Dont count decimal as sig fig...
{
length -= 1;
}
if ([[_textfield1 text] doubleValue] == 0.0)
{
NSLog(@"HERE");
self.display3.text = @"1";
}
NSString *siggy = [NSString stringWithFormat:@"%i", length];
self.display3.text = siggy;
}
if ([thetextfield.text length] == 0)
{
length = 0;
NSString *ifzero = [NSString stringWithFormat:@"%i", length];
self.display3.text = ifzero;
}
if ([[thetextfield text] doubleValue] == 0.0)
{
newLength = 1;
NSString *zeroVal = [NSString stringWithFormat:@"%i", newLength];
self.display3.text = zeroVal;
}
NSString *norm = [NSString stringWithFormat:@"%i", length];
self.display3.text = norm;
}
}
请帮帮忙,我相信它有事情做与数字在内存中表现的方式......但NSLog的工作时,我把它放在一个while语句...任何输入赞赏。
谢谢
什么崩溃:
最后,如果也可以很容易地从转换?崩溃日志在哪里? – 0x8badf00d 2012-04-20 03:14:57
真的没有崩溃日志,它的输出是“terminate called throwing an exception”并且iOS Simulator退出。 – JoeyLaBarck 2012-04-20 03:33:33