我有一个使用UITableViewController的应用程序,它显示按字母顺序分隔成各个部分的所有50个状态的列表。我已将详细信息公开按钮添加到故事板中的原型单元格,并且该表格显示了所有正确的信息。
当我按下单元格上的按钮时,它应该转到新的viewController并显示状态名称作为视图标题,然后在视图中显示车牌照片。
我正在使用 - (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath方法来控制按钮然后我使用 - (void)prepareForSegue:(UIStoryboardSegue *)segue发送者: (id)sender来控制传递给新viewController的值。
我遇到的问题是,当我按下详细信息披露按钮时,没有任何内容通过。 NSLogging新viewController输出(null),(null)中的值,视图没有标题或图片。但是,当我按下然后第二次按下同一个单元格的详细信息按钮时,它会像它应该的那样工作。标题正确,图片显示正确。
当我选择另一个单元格时也是如此,viewController显示发送的最后一个信息,我必须按回然后再选择单元格进行更新。当第一次选择不同的单元格时,(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];
}
}
对此的任何帮助将不胜感激。
答案 0 :(得分:0)
检查首先触发的方法。也许你在执行segue之后设置了属性。
没有关于你何时(何时)执行segue的信息。
您可以将此行添加到accessoryButton方法:
[self performSegueWithIdentifier:yourIdentifierFromStoryboard sender:self];