How I can use the Detail Disclosure Button whith Storyboard?

我与影子孤独终老i 提交于 2019-12-08 03:36:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!