Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 必须按下详细信息披露按钮两次,才能使用prepareForSegue方法传递数据_Ios_Objective C_Xcode_Uitableview_Segue - Fatal编程技术网

Ios 必须按下详细信息披露按钮两次,才能使用prepareForSegue方法传递数据

Ios 必须按下详细信息披露按钮两次,才能使用prepareForSegue方法传递数据,ios,objective-c,xcode,uitableview,segue,Ios,Objective C,Xcode,Uitableview,Segue,编辑:我已经解决了这个问题。已更正代码以显示此修复程序 我有一个应用程序,它使用UITableViewController,按字母顺序显示所有50个州的列表。我已经在故事板的原型单元中添加了详细信息披露按钮,表格显示了所有正确的信息 当我按下单元格上的按钮时,它应切换到新的viewController,并将状态名称显示为视图标题,然后在视图中显示车牌图片 我使用-(void)tableView:(UITableView*)tableView accessorybuttonattappedforr

编辑:我已经解决了这个问题。已更正代码以显示此修复程序

我有一个应用程序,它使用UITableViewController,按字母顺序显示所有50个州的列表。我已经在故事板的原型单元中添加了详细信息披露按钮,表格显示了所有正确的信息

当我按下单元格上的按钮时,它应切换到新的viewController,并将状态名称显示为视图标题,然后在视图中显示车牌图片

我使用-(void)tableView:(UITableView*)tableView accessorybuttonattappedforrowwithindexath:(NSIndexPath*)indexPath方法来控制按钮按下,然后使用-(void)prepareforsgue:(UIStoryboardSegue*)segue sender:(id)sender来控制传递给新viewController的值

我遇到的问题是,当我按下“详细信息披露”按钮时,什么都没有通过。n记录新viewController输出(null)、(null)中的值,并且视图没有标题或图片。然而,当我按下后退键,然后第二次按下同一单元格的“详细信息披露”按钮时,它的工作方式应该是这样的。标题正确,图片显示正确

当我选择另一个单元格时也是如此,viewController显示最后发送的信息,我必须按back键,然后再次选择该单元格以进行更新。当第一次选择一个不同的单元格时,(null,(null)是NSlog输出的。所以我相信发生的是,第一次按下详细信息披露按钮时,没有传递值,但第二次按下时,传递值

以下是相关代码:

-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
    //Don't even use this method now.
}

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
UITableViewCell *cell = (UITableViewCell*)sender;  //Added this line
self.path = [self.tableview indexPathForCell:cell]; //Added this line

if ([segue.identifier isEqualToString:@"stateSegue"])
    {
        self.controller = segue.destinationViewController;
        self.controller.stateName = [self.stateArray[indexPath.section][indexPath.row]stateName];
        self.controller.licensePlateURL = [self.stateArray[indexPath.section][indexPath.row]licensePlateURL];
    }
}

如果您有任何帮助,我们将不胜感激。

请检查先触发哪个方法。也许您可以在执行segue后设置属性

没有关于你是如何(何时)执行segue的信息

您可以将此行添加到accessoryButton方法:

[self performSegueWithIdentifier:yourIdentifierFromStoryboard sender:self];

实际上我已经解决了这一部分。我甚至不再使用accessoryButtonTapped方法。我编辑代码来显示工作的“方法”。