gpt4 book ai didi

objective-c - UIAlertView 添加 NSString

转载 作者:行者123 更新时间:2023-12-02 21:51:45 26 4
gpt4 key购买 nike

我想将字符串添加到我的 UIAlertView 消息中


-(void) errorState:(NSException *) exp
{
NSLog(@"Error State Blood Level3 %@",exp);
NSString * myString = (NSString*)exp;
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:myString delegate:self cancelButtonTitle:@"Go to the main menu" otherButtonTitles:nil];
[alert show];
[alert release];<p></p>

}

but it throws


2010-07-15 12:48:34.721 kndFrameV02[7955:207] -[NSException isEqualToString:]: unrecognized selector sent to instance 0x707b2e0
2010-07-15 12:48:34.724 kndFrameV02[7955:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSException isEqualToString:]: unrecognized selector sent to instance 0x707b2e0'

那么如何将字符串变量添加到 UIAlertView 的消息中?

最佳答案

当您将其转换为一个 NSException 时,它不会突然变成 NSStringNSException 有一个名为 reason 的属性,这就是您需要的属性。像这样使用它:NSString *reason = exp.reason;

关于objective-c - UIAlertView 添加 NSString,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3254400/

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