UIAlertview不接受字符串作为消息



我收到了来自Web服务的响应,但UIAlertview给出了一个奇怪的错误

我已经打印了回复,就在下面我打电话给

2013-08-13 15:40:27.463 Ipad Qld[1459:907] Result {
    msg = "Form has been sent successfully.";
    status = SUCCESS;
}
2013-08-13 15:40:27.465 Ipad Qld[1459:907] -[__NSDictionaryM isEqualToString:]: unrecognized selector sent to instance 0x1f1168e0
2013-08-13 15:40:27.467 Ipad Qld[1459:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryM isEqualToString:]: unrecognized selector sent to instance 0x1f1168e0'
*** First throw call stack:
(0x32dad2a3 0x3ac1197f 0x32db0e07 0x32daf531 0x32d06f68 0x34bb9375 0x34d05c95 0x34d05741 0x6a25b 0x32cfe037 0x336ae2cb 0xa013f 0x9fe35 0x8d1e7 0x336e86fd 0x336281f9 0x33628115 0x32a8a45f 0x32a89b43 0x32ab1fcb 0x32cf374d 0x32ab242b 0x32a1603d 0x32d82683 0x32d81f7f 0x32d80cb7 0x32cf3ebd 0x32cf3d49 0x368aa2eb 0x34c09301 0x43a85 0x3b048b20)
libc++abi.dylib: terminate called throwing an exception

代码是

- (void) contactUsNotificationReceived:(NSNotification *) notification
{
    [[ActivityIndicator currentIndicator] hide];
    NSDictionary *alertMessage = [notification userInfo];
    NSString * alertMessageString = alertMessage[@"NSLocalizedString"];
    NSLog(@"Result is waga %@",alertMessageString);
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Result" message:alertMessageString delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
    [alert show];
}

看起来您正在传递一个NSDictionnary。猜测,尝试改变:

NSString * alertMessage; // the object that you think is a NSString

NSDictionary * alertMessage;
NSString * alertMessageString = alertMessage[@"msg"];

祝你好运。

您的代码在isEqualToString中似乎有问题。源字符串无效,或者它已释放,或者它现在指向Dictionary

可能是您的警报字符串(您想要描述)它不是NSString,但可能是NSDictionary,所以请检查它。

首先将您的警报消息从NSDictionary获取到NSString。。。

  NSString *alertMessage = [yourDict objectForKey:@"yourKey"];

现在,在警报中显示您的警报消息。。。

  UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"%@",alertMessage] message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
  [alert show];

我希望这对你有帮助。

最新更新