У меня есть TableView с пользовательской ячейкой и заголовком раздела. Заголовок показывает мне страну, и пользовательская ячейка показывает мне Город.Как определить кнопку в пользовательском UITableViewCell?
, который выглядит следующим образом:
Если США
Нью-Йорк
Лос-Анджелес
Германия
Berlin
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. он покажет мне первый город в первом разделе.
Надеюсь, вы можете мне помочь.
Возможный дубликат [Как передать UITableView IndexPath в UIButton @selector по параметрам в iOS?] (Http://stackoverflow.com/questions/11936126/how-to-pass-uitableview-indexpath-to-uibutton-selector -by-parameters-in-ios) – TheTiger