我得到在4小時內瘋狂,我真的需要幫助剛開EXC_BAD_ACCESS。下面是代碼:同時使用的NSString
- (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] retain];」不要忘了釋放它時dealloc – adali 2012-04-28 06:48:58
對不起,我不使用ARC,或者他可以使用屬性來解決問題, – adali 2012-04-28 06:57:05