0

単純な Web サイト データをファイルに保存するのに問題があります。シンタックスは正しいと思います。誰か助けてくれませんか? 実行すると、データが取得されたことが示されますが、保存するはずのファイルを終了して開くと、何も入っていません。

- (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;

}
4

1 に答える 1

0

これがあなたの質問に答えているかどうかはわかりませんが、あなたのコードには 2 つの問題があります。まず、resignFirstResponder のドキュメントには、「このメソッドを直接呼び出さないでください」と記載されています。2 つ目は、独自のアプリ バンドルに保存しようとしているようですが、それはダメです。バンドルを読み取り専用と考えてください。

于 2010-06-05T21:47:17.760 に答える