2010-06-05 6 views
0

간단한 웹 사이트 데이터를 파일로 저장하는 데 문제가 있습니다. 나는 sintax가 정확하다고 누군가가 나를 도울 수 있다고 믿는가? 내가 그것을 실행할 때, 그것은 데이터를 가져 오는 것을 보여 주지만, 내가 끝내고 저장할 파일을 열면 아무 것도 없다.파일에 NSString 저장

- (BOOL)textFieldShouldReturn:(UITextField *)nextField { 

[timer invalidate]; 
startButton.hidden = NO; 
startButton.enabled = YES; 
stopButton.enabled = NO; 
stopButton.hidden = YES; 
stopLabel.hidden = YES; 
label.hidden = NO; 
label.text = @"Press to Activate"; 

[nextField resignFirstResponder]; 

NSString *urlString = textField.text; 

NSData *dataNew = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlString]]; 

NSUInteger len = [dataNew length]; 

NSString *stringCompare = [NSString stringWithFormat:@"%i", len]; 

NSLog(@"%@", stringCompare); 



NSString *filePath = [[NSBundle mainBundle] pathForResource:@"websiteone" ofType:@"txt"]; 
if (filePath) { 
    [stringCompare writeToFile:filePath atomically:YES encoding:NSUTF8StringEncoding error:NULL]; 
    NSString *myText = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:NULL]; 
    NSLog(@"Saving... %@", myText); 
} 
else { 
    NSLog(@"cant find the file"); 
} 


return YES; 

} 

답변

0

이 질문에 대한 답변을 모르겠지만 코드에 2 가지 문제점이 있습니다. 첫째, resignFirstResponder에 대한 문서에서는 "이 메서드를 직접 호출하지 마십시오."라고 말합니다. 둘째, 자신의 앱 번들에 저장하려고하는 것 같습니다. 그럴 수는 없습니다. 번들은 읽기 전용으로 간주하십시오.