1

我尝试将 Detail Disclosure Button 与 Storyboard 一起使用,但是当我构建从 Disclosure Button 到新视图的 segue 时,它​​仅在我按下表格单元格时才有效,而不是在我按下 Detail Disclosure Button 时。

我必须做什么?

谢谢,

伯恩哈德

4

2 回答 2

5

我可能错了,但我发现它需要通过 UITableDelegate 代码来实现:

#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];
}

然后在你的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

     }
}
于 2012-06-28T01:23:05.477 回答
0

skinnyTOD 的回答很好。但我不知道为什么 self.sequenceTableView.indexPathForSelectedRow; 返回 nil(0x0000000),我必须使用属性将 selectedRow 保存在 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
    }
}
于 2012-12-31T12:36:38.527 回答