在UITableView的didSelectRow之前调用Storyboard segue [英] Storyboard segue gets called before UITableView's didSelectRow

查看:125
本文介绍了在UITableView的didSelectRow之前调用Storyboard segue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有来自表格单元格的segue的故事板。我想在选择一行时设置一些属性,所以我执行以下操作:

   - (void)tableView: (UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
[[ProperyManager sharedPropertyManager] setSelectedRow:[verseIds objectAtIndex:indexPath.row]];
[[ProperyManager sharedPropertyManager] setID:[poemIDs objectAtIndex:indexPath.row]];
[[ProperyManager sharedPropertyManager] setRowToReturn:[NSString stringWithFormat:@%i,indexPath.row]];


}

问题是,视图控制器生命周期目标视图控制器的方法(viewWillAppear等)在上面的didSelectRow方法之前调用,因为segue在执行委托方法之前推送视图。



我怎样才能解决这个问题?

解决方案

不要从Cell创建Segue到新VC,而不是将Segue从旧VC设置为新VC并给segue一个标识符。



然后在

didSelectRowAtIndexPath 您可以致电



[self performSegueWithIdentifier:@Segue发送者:自我]


I have a storyboard with segue from a table cell. I want to set some properties with some data when a row gets selected so I do the following:

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [[ProperyManager sharedPropertyManager]setSelectedRow:[verseIds objectAtIndex:indexPath.row]];
    [[ProperyManager sharedPropertyManager]setID:[poemIDs objectAtIndex:indexPath.row]];
    [[ProperyManager sharedPropertyManager]setRowToReturn:[NSString stringWithFormat:@"%i",indexPath.row]];


}

The problem is, the view controller lifecycle methods (viewWillAppear etc.) of the destination view controller get called before the didSelectRow method above, because the segue pushes the view before the delegate method is executed.

How can I get around this?

解决方案

Don't create the Segue from the Cell to the new VC, instead set the Segue from the old VC to the new VC and give the segue an identifier.

Then within

didSelectRowAtIndexPath you can call

[self performSegueWithIdentifier:@"Segue" sender:self]

这篇关于在UITableView的didSelectRow之前调用Storyboard segue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆