1

困っているか、必要な情報が見つからないだけです。「saveDataround」ボタンを選択したときに配列に保存したいオブジェクトがありますが、オブジェクトにテキストを入力する方法がわかりません」 Round": "Expected identifier" と "Expected , ;" を取得しています。コードの 1 行目と 2 行目にエラーがあります。前もって感謝します。

[NSString *roundChoice = [NSString stringWithFormat:@"Round"];
self.round.text = roundChoice;]

- (IBAction)saveDataround {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *recipient = [NSString stringWithFormat:@"%@/arrayChoiceRound", documentsDirectory];
    NSMutableArray *array = [[NSMutableArray alloc] init];
    [array addObject:round.text];
    [array writeToFile:recipient atomically:NO];
}
4

1 に答える 1

1

最初の 2 行のコードはどこに実装されていますか? 彼らは何をすべきですか?

詳細情報なしで上記のコードを変更する方法は次のとおりです。

// remove "[" from start of line & no need to use stringWithFormat here
NSString *roundChoice = @"Round";

// remove "]" from end of line
self.round.text = roundChoice;

- (IBAction)saveDataround {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];

    // use stringByAppendingPathComponent here
    NSString *recipient = [documentsDirectory stringByAppendingPathComponent:@"arrayChoiceRound"];
    NSMutableArray *array = [[NSMutableArray alloc] init];

    // use self here (not required)
    [array addObject:self.round.text];

    [array writeToFile:recipient atomically:NO];

    // release the array
    [array release];
}
于 2010-01-25T23:40:11.540 に答える