plist 파일을 만들고 데이터를 쓰고 아래 코드를 사용하여 데이터를 읽으려고하는데 어떻게 든 앱이 다운됩니다. 문자열 값을 저장하려고합니다. 사람이 맞다까지 우리가 작업을 위해, 당신은 충분한 데이터를 제공하지 않았다 내가 얻을plist 파일 도움말
//PLIST FILE START..
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //1
NSString *documentsDirectory = [paths objectAtIndex:0]; //2
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"data.plist"]; //3
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath: path]) //4
{
NSString *bundle = [[NSBundle mainBundle] pathForResource:@"data" ofType:@"plist"]; //5
[fileManager copyItemAtPath:bundle toPath: path error:&error]; //6
}
//And write data:
NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithContentsOfFile: path];
//here add elements to data file and write data to file
//NSString *value = rowValue;
[data setObject:[NSString stringWithFormat:@"%@", rowValue] forKey:@"value"];
[data writeToFile: path atomically:YES];
[data release];
//Read Data..
NSMutableDictionary *savedStock = [[NSMutableDictionary alloc] initWithContentsOfFile: path];
//load from savedStock example int value
NSString *test;
test = [savedStock objectForKey:@"value"];
[savedStock release];
NSLog(@"PLIST VALUE:%@",test);
//PLIST FILE END..
오류,
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString stringValue]: unrecognized selector sent to instance 0x4b25af0' *** Call stack at first throw: ( 0 CoreFoundation 0x00dd9be9 __exceptionPreprocess + 185 1 libobjc.A.dylib 0x00f2e5c2 objc_exception_throw + 47 2 CoreFoundation 0x00ddb6fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187 3 CoreFoundation 0x00d4b366 ___forwarding___ + 966 4 CoreFoundation 0x00d4af22 _CF_forwarding_prep_0 + 50 5 Gavel Edge 0x00003e1e -[JobViewController tableView:didSelectRowAtIndexPath:] + 832 6 UIKit 0x00358794 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1140 7 UIKit 0x0034ed50 -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 219 8 Foundation 0x000617f6 __NSFireDelayedPerform + 441 9 CoreFoundation 0x00dbafe3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 19 10 CoreFoundation 0x00dbc594 __CFRunLoopDoTimer + 1220 11 CoreFoundation 0x00d18cc9 __CFRunLoopRun + 1817 12 CoreFoundation 0x00d18240 CFRunLoopRunSpecific + 208 13 CoreFoundation 0x00d18161 CFRunLoopRunInMode + 97 14 GraphicsServices 0x0170e268 GSEventRunModal + 217 15 GraphicsServices 0x0170e32d GSEventRun + 115 16 UIKit 0x002f142e UIApplicationMain + 1160 17 Gavel Edge 0x00001de4 main + 102 18 Gavel Edge 0x00001d75 start + 53 19 ??? 0x00000001 0x0 + 1 ) terminate called after throwing an instance of 'NSException'
"어떻게 든 앱이 다운됩니다"라는 표현은 전혀 도움이되지 않습니다. 디버거를 사용해 보시고 그 어플리케이션이 충돌하고있는 지점을 정확하게 찾으시기 바랍니다. – Till
어떤 라인이 충돌합니까? 어떤 오류가 있습니까? – GoatInTheMachine
죄송합니다. 코드를 편집하여 오류를 추가했습니다. – developer