これは私の最初の質問です。私は尋ねませんが、ドキュメントを読み、スタックオーバーフローから多くのコードを試した後、私はまだ困惑しています. 私は最近コードの学習を始めたばかりなので、そうです。
私がやろうとしていること: カスタムセルの textField に数値が入力され、終了時に CustomCellClass.m で saveGoal メソッドが呼び出されます (以下に示すコード)。saveGoal メソッドは、前のエントリのテキスト ファイルから goalArray を作成します (データがない場合、テキスト ファイルが作成されます。このコードは機能するため省略しました)。ここが難しいところです(私にとって)。ユーザーエントリを挿入できるように、メソッドを呼び出したセルの indexPath が必要です...しかし、indexPathForCell でパラメーターとして使用するセルオブジェクトを取得する方法がわかりません。
- (IBAction)saveGoal:(id)sender {
// Saving the user entry in a string
self.goalString = [NSString stringWithFormat:@"%@\n",self.goal.text];
// Instance variables
NSError *err = nil;
NSMutableArray *goalsArray = [NSMutableArray arrayWithContentsOfURL:self.goalsURLMethod];
// If there is data in the text file
NSIndexPath *indexPath = [[NSIndexPath alloc] init];
// Ideally I'd like to do something like this (There is an IBOutlet from the
// table view in the storyboard to a tableView property).
indexPath = [self.tableView indexPathForCell: UNKNOWN CELL PARAMETER];
// Then based on the indexPath I can insert or replace objects in the array
if(indexPath == 0) {
// masterful code
} else {
// If it's another row, replace the object. Something like this:
[goalsArray replaceObjectAtIndex: indexPath.row withObject: self.goalString];
[goalsArray writeToURL:self.goalsURLMethod atomically:YES];
// Then update the view
[self.tableView reloadData];
}
}
}
解決策をいただければ幸いです。