gpt4 book ai didi

iphone - 从详细信息披露按钮 segue 传递对象

转载 作者:可可西里 更新时间:2023-11-01 05:38:01 25 4
gpt4 key购买 nike

如何将对象从详细信息披露分流器传递到详细信息 View Controller ?对此有什么建议或快速修复吗?理想情况下,我想创建这样的方法:

[self performSegueWithIdentifier:@"showDetail" sender:self passObject:object];

原因是“准备继续”似乎只有在我按下详细信息披露指示器之前的单元格时才会被调用。我将如何创建一个像上面这样的方法来创建下面准备的效果?

if ([[segue identifier] isEqualToString:@"showDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
id object = [_objects objectAtIndex:indexPath.row];
[[segue destinationViewController] setDetailItem:object];
}

我已经尝试像这样创建 UIStoryboardSegue 的子类,但遇到了两个问题。

@implementation masterToDetail
-(void)performSegueWithIdentifier:(NSString*)identifier sender:(id)sender passObject:(id)object{
[self.destinationViewController setDetailItem:object];
[self performSegueWithIdentifier:identifier sender:sender];
}

-(void)performSegueWithIdentifier:(NSString*)identifier sender:(id)sender{
//What code should go here? Issue one
}

-(void)perform{
//Second issue, the compiler will crash and say I need to override perform.
}

最佳答案

我通过完全放弃 segue idea 的子类解决了这个问题。我删除了自定义 segue 并将推送 segue(从 tableviewcontrollre)推送到我的详细 View Controller 。然后我创建了一个实例变量 NSIndexPath* _ipath; 我的代码如下:

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath{
_ipth = indexPath;
[self performSegueWithIdentifier:@"showDetail" sender:self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
NSLog(@"prepping");
if ([[segue identifier] isEqualToString:@"showDetail"]) {
NSLog(@"in if");
id object = [_objects objectAtIndex:_ipth.row];
[[segue destinationViewController] setDetailItem:object];
}
}

这可以让 segue 为正确的单元格工作做好准备。

关于iphone - 从详细信息披露按钮 segue 传递对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11197295/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com