问题
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
回答1:
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
}
}
回答2:
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
}
}
来源:https://stackoverflow.com/questions/11234373/how-i-can-use-the-detail-disclosure-button-whith-storyboard