나는 Custom Cell과 Section Header가있는 TableView를 가지고있다. 헤더는 나에게 국가를 보여주고 사용자 지정 셀은 나에게 도시를 보여줍니다.커스텀 UITableViewCell에서 버튼 클릭을 결정하는 방법은 무엇입니까?
는 다음과 같이 :
미국에게
뉴욕
로스 앤젤레스
독일
을
베를린
Frakfurt
모든 셀은 버튼을 얻었다. 언론을보고 나면 도시 이름을 탐색하여 상세보기로 푸시합니다.
문제는 버튼을 누른 후 도시 이름을 결정하는 방법을 모르겠다는 것입니다.
나는 해결책을했지만, 그것은 더 이상 작동하지 않습니다- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSManagedObject *managedObject = [self.fetchedResultsController objectAtIndexPath:indexPath];
StandortCell *cell = (StandortCell *)[tableView dequeueReusableCellWithIdentifier:@"ortCell"];
[cell.detailButton setTag:indexPath.row];
cell.ortLabel.text = [managedObject valueForKey:@"stadtname"];
}
- (IBAction)detailButton:(id)sender {
UIView *contentView = [sender superview];
UITableViewCell *cell = (UITableViewCell *)[contentView superview];
NSIndexPath *cellIndexPath = [self.tableView indexPathForCell:cell];
NSInteger section = cellIndexPath.section;
UIButton * myButton = sender;
int row=myButton.tag;
NSIndexPath * indexPath = [NSIndexPath indexPathForRow:row inSection:section];
StrasseViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:@"strasse"];
self.selectedStandort = [self.fetchedResultsController objectAtIndexPath:indexPath];
detail.currentStandort = self.selectedStandort;
[self.navigationController pushViewController:detail animated:YES];
}
난 내 예전의 코드를 사용할 때 그것은 단지 첫 번째 섹션에서 정확한 거리 행을 표시합니다. 그것은 다른 섹션 (국가)을 감지하지 못했습니다.
내가 thirt 섹션에서 첫 번째 도시를 선택했을 때. 그것은 첫 번째 섹션에서 첫 번째 도시를 표시합니다.
도와 주시면 감사하겠습니다.
가능한 [iOS의 매개 변수로 UITableViewPathPath를 @ selector로 전달하는 방법] (http://stackoverflow.com/questions/11936126/how-to-pass-uitableview-indexpath-to-uibutton-selector) -by-parameters-in-ios) – TheTiger