을 호출하면 셀의 textField에서 indexPath를 가져 오는 방법이 내 첫 번째 질문입니다. 묻지는 않겠지 만 문서를 읽고 스택 오버플로에서 많은 코드를 시도한 후에도 난처한 상태입니다. 나는 최근에 코드를 배우기 시작 했으므로 근본적인 오류 (들)를 만들었다면 놀라지 않을 것입니다.didEndOnExit에서 사용자 정의 메서드
사용자 삽입 이미지 사용자 정의 셀의 textField에서 숫자를 입력하고 종료 할 때 saveGoal 메서드가 CustomCellClass.m (아래 코드)에서 호출됩니다. saveGoal 메서드는 이전 항목의 텍스트 파일에서 goalsArray를 만듭니다 (텍스트 파일이 만들어지지 않은 데이터가 없으면 작동하지 않으므로 생략했습니다). 이것은 어려운 곳입니다 (나를 위해). 메서드를 호출하는 셀의 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];
}
}
}
해결책이 많이 있습니다.
@property (strong, nonatomic) NSIndexPath *indexPath;
을하고 표시 셀을 반환 할 때 설정 :
감사, 일 가장 우아한 해결책 인 것 같습니다. 후속 질문이 있습니다. NSIndex 속성 (CustomCellClass의 customIndexPath)을 만들었습니다. 그런 다음 cellForRowAtIndexPath에서 CustomCellClass의 클래스 인스턴스를 만들고 다음과 같이 속성을 설정하려고했습니다. [CustomeCellClassInstance setCustomIndexPath : indexPath]; 그러나 NSLog customIndexPath 때 그것은 null을 반환합니다. 내가 뭘 놓치고 있니? –
반환 할 셀 인스턴스가 이미 있어야합니다. 그것은 당신이 속성을 설정 한 인스턴스입니까? – Wain