我在 4 小时内变得疯狂,我真的需要帮助。这是代码:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
//check if strGroup has prefix and suffix #
BOOL result;
result = [strGroup hasPrefix: @"#"];
if (result)
{
result = [strGroup hasSuffix: @"#"];
if (result)
{
NSMutableString* string = [NSMutableString stringWithString: strGroup];
str = [strGroup substringWithRange: NSMakeRange (1, [string length]-2)];
strToHoldAllContact = [NSString stringWithFormat:@"%@",str];
}
}
NSLog(@"strToHoldAllContact=%@",strToHoldAllContact);
}
我正确获取了 strToHoldAllContact
的值。但是当我尝试从另一种方法访问 strToHoldAllContact
时,我收到错误:
[CFString respondsToSelector:]: message sent to deallocated instance 0x856f2a0
最佳答案
使用
strToHoldAllContact = [NSString stringWithFormat:@"%@",str];
[[strToHoldAllContact retain] autorelease];
忘记发布。
关于ios - 使用 nsstring 时获取 EXC_BAD_ACCESS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10361297/