How I can use the Detail Disclosure Button whith Storyboard?
-
17-06-2021 - |
Pregunta
I try to use the Detail Disclosure Button with the Storyboard, but when I build a segue from Disclosure Button to a new View it works only, when I press the table cell and not, when I press the Detail Disclosure Button.
What must I do?
Thanks,
Bernhard
Solución
I may be wrong but I have found that it needs to be implemented through UITableDelegate code:
#pragma mark - Table view delegate methods
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
// do a segue based on the indexPath or do any setup later in prepareForSegue
[self performSegueWithIdentifier:@"segueName" sender:self];
}
And then in your prepareForSegue
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:@"segueName"]){
NSIndexPath * indexPath = self.sequenceTableView.indexPathForSelectedRow;
// do some prep based on indexPath, if needed
}
}
Otros consejos
skinnyTOD's answer is fine. But I don't know why self.sequenceTableView.indexPathForSelectedRow; returns nil(0x0000000), I have to use a property to save the selectedRow in accessoryButtonTappedForRowWithIndexPath:
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
// do a segue based on the indexPath or do any setup later in prepareForSegue
self.selectedRow = indexPath.row;
[self performSegueWithIdentifier:@"segueName" sender:self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"segueName"]) {
// use self.selectedRow here
}
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow