我有一些代碼,看起來像這樣:崩潰錯誤幫助的NSString
NSString *_parse = [NSString stringWithFormat:@"//%@",_user];
NSString *_status = [Parser parse:_parse:@"status"]; //parses the xml
if ([_status isEqualToString:@"1"]) { //error here
}
應用程序崩潰時,它會檢查,如果兩個字符串相等。然而,當我更換的代碼與此第一線能正常工作:
NSString *_parse = [NSString stringWithFormat:@"//user1"];
但不使用「用戶」伊娃,我需要使用,因爲值可以是不同的。 ivar「用戶」是一個NSString,聲明較早[self setUser:@"userX"];
我應該怎麼做才能解決這個問題?由於
編輯:這裏是解析XML代碼:
+ (NSString *)dataFilePath:(BOOL)forSave {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *documentsPath = [documentsDirectory stringByAppendingPathComponent:@"hangout.xml"];
return documentsPath;
}
+ (MyViewController *)parse:(NSString *)nodesForPath:(NSString *)elementsForName {
NSString *filePath = [self dataFilePath:FALSE];
NSData *xmlData = [[NSMutableData alloc] initWithContentsOfFile:filePath];
NSError *error;
GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithData:xmlData options:0 error:&error];
if (doc == nil) { return nil; }
MyViewController *view = [[[MyViewController alloc] init] autorelease];
NSArray *getVersionInfo = [doc nodesForXPath:nodesForPath error:nil];
for (GDataXMLElement *versionInfo in getVersionInfo) {
NSArray *elm1 = [versionInfo elementsForName:elementsForName];
GDataXMLElement *elm2 = (GDataXMLElement *) [elm1 objectAtIndex:0];
return elm2.stringValue;
}
[doc release];
[xmlData release];
return view;
}
請發佈應用程序崩潰時獲得的錯誤消息以及設置_user變量的代碼。 – Jim 2011-02-18 21:34:02