【发布时间】:2009-04-13 16:28:10
【问题描述】:
我在我的应用程序中使用 NSString 时遇到了一些困难。基本上,我有一个名为 o1string 的 NSString,其中包含值“602”。我想在 UIAlertView 中与其他一些文本一起输出它。
votedmessage = [ NSString stringWithFormat:@"The current standings are as follows:\n\n%@: %@ votes", b1title, o1string ];
UIAlertView *votedAlert = [[UIAlertView alloc] initWithTitle:@"Thank you for voting" message:votedmessage delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
我使用了 NSLog 并验证了 NSString 中的值肯定是 602,而消息中使用的另一个变量(b1title)可以自行输出。但是,当我将 o1votes 变量添加到警报消息时,我无法弄清楚为什么应用程序会崩溃,这是否与仅在 NSString 中保存一个数字的冲突有关?
这就是 o1string 的设置方式。它肯定包含从 XML 文件中获取的“602”。
o1string = [[options objectAtIndex:3] objectForKey: @"votes"];
o1string = [o1string stringByReplacingOccurrencesOfString:@"\n" withString:@""];
o1string = [o1string stringByReplacingOccurrencesOfString:@" " withString:@""];
【问题讨论】:
-
您发布的代码中没有 o1votes 变量。贴出分配变量的代码以及如何使用它。
-
对不起,我是说 o1string。原帖已更新。
-
它们都是 NSString。我测试了他们两个。我将 UIAlertView 标题设置为 o1string 并且它崩溃了,但是当我将它设置为 b1title(它也是一个以完全相同的方式填充数据的 NSString)时,它按预期运行。
-
o1string 和 b1title 的唯一区别是 o1string 包含“602”,而 b1title 包含“Jack Escuda”。我认为这是因为 o1string 仅包含一个无法正常工作的数字。
-
您应该更清楚正在发生的事情。有什么例外?堆栈?
标签: iphone objective-c nsstring