カスタムセルとセクションヘッダーを持つTableViewがあります。ヘッダーには国が表示され、カスタム セルには都市が表示されます。
次のようになります。
アメリカ合衆国
ニューヨーク
ロサンゼルス
ドイツ
ベルリン
フランクフルト
すべてのセルにボタンがあります。押すとナビゲートされ、都市名が詳細ビューにプッシュされます。
問題は、ボタンを押した後に都市名を特定する方法がわからないことです。
解決策はありましたが、もう機能しません:
- (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];
}
古いコードを使用すると、最初のセクションに正しい通りの行が表示されます。他のセクション(国)は検出されませんでした。
3 番目のセクションで最初の都市を選択したとき。最初のセクションの最初の都市が表示されます。
あなたが私を助けてくれることを願っています。