xcode 我如何使用故事板的详细信息披露按钮?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11234373/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How I can use the Detail Disclosure Button whith Storyboard?
提问by Bernhard B
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.
我尝试将 Detail Disclosure Button 与 Storyboard 一起使用,但是当我构建从 Disclosure Button 到新视图的 segue 时,它仅在我按下表格单元格时起作用,而不是在按下 Detail Disclosure 按钮时起作用。
What must I do?
我必须做什么?
Thanks,
谢谢,
Bernhard
伯恩哈德
回答by spring
I may be wrong but I have found that it needs to be implemented through UITableDelegate code:
我可能错了,但我发现它需要通过 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];
}
And then in your prepareForSegue
然后在你的 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
}
}
回答by Jake Lin
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:
skinnyTOD 的回答很好。但我不知道为什么 self.sequenceTableView.indexPathForSelectedRow; 返回 nil(0x0000000),我必须使用一个属性将 selectedRow 保存在 AccessoriesButtonTappedForRowWithIndexPath 中:
- (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
}
}