gpt4 book ai didi

iphone - selectedSegmentIndex使我的应用崩溃

转载 作者:行者123 更新时间:2023-12-03 15:52:56 26 4
gpt4 key购买 nike

我有一个UISegmentedControl,每当我触摸一个按钮时,它就会显示一个带有当前所选分段索引的警报:

- (IBAction)bOkayTouched:(id)sender
{
NSString *msg = [NSString stringWithFormat:@"%@", [scRPSSL selectedSegmentIndex]];
UIAlertView *lol = [[UIAlertView alloc] initWithTitle:@"Mkay" message:msg delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:nil];
[lol show];
[lol release];
}

但是,该应用程序在必须创建NSString时崩溃。但是当我用以下命令替换该行时,它不会崩溃:
NSString *msg = [NSString stringWithFormat:@"XD"];

或类似。

哦,这是调试器告诉我的:
[Session started at 2009-08-30 21:04:38 +0200.]

[Session started at 2009-08-30 21:04:43 +0200.]
GNU gdb 6.3.50-20050815 (Apple version gdb-966) (Tue Mar 10 02:43:13 UTC 2009)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i386-apple-darwin".sharedlibrary apply-load-rules all
Attaching to process 4630.
unable to read unknown load command 0x80000022
unable to read unknown load command 0x80000022
unable to read unknown load command 0x80000022
unable to read unknown load command 0x80000022
unable to read unknown load command 0x80000022
unable to read unknown load command 0x80000022
unable to read unknown load command 0x80000022
unable to read unknown load command 0x80000022
unable to read unknown load command 0x80000022
unable to read unknown load command 0x80000022
unable to read unknown load command 0x80000022
unable to read unknown load command 0x80000022
unable to read unknown load command 0x80000022
unable to read unknown load command 0x80000022
unable to read unknown load command 0x80000022
unable to read unknown load command 0x80000022
unable to read unknown load command 0x80000022
unable to read unknown load command 0x80000022
unable to read unknown load command 0x80000022
unable to read unknown load command 0x80000022
unable to read unknown load command 0x80000022
unable to read unknown load command 0x80000022
unable to read unknown load command 0x80000022
unable to read unknown load command 0x80000022
unable to read unknown load command 0x80000022
unable to read unknown load command 0x80000022
unable to read unknown load command 0x80000022
unable to read unknown load command 0x80000022
unable to read unknown load command 0x80000022
unable to read unknown load command 0x80000022
unable to read unknown load command 0x80000022
unable to read unknown load command 0x80000022
unable to read unknown load command 0x80000022
unable to read unknown load command 0x80000022
unable to read unknown load command 0x80000022
unable to read unknown load command 0x80000022
unable to read unknown load command 0x80000022
unable to read unknown load command 0x80000022
unable to read unknown load command 0x80000022
unable to read unknown load command 0x80000022
(gdb)

谁能帮我?

此外,如果所选索引为0(零),则警报会显示“(空)”。

谢谢!

最佳答案

selectedSegmentIndex可能是整数值,在这种情况下,格式字符串%@不是正确的选择。请尝试以下操作:

[NSString stringWithFormat:@"%d", [scRPSSL selectedSegmentIndex]];

可以在Apple的 format specifiers开发人员文档中找到更多信息,但要点是 %@仅用于 NSObject的子类。它通过调用 [object description]返回字符串来工作。如果在整数值上使用它,则实际上是在向不是对象的对象发送Objective-C消息,这将导致 undefined 的行为(通常是崩溃)。

关于iphone - selectedSegmentIndex使我的应用崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1354635/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com