【问题标题】:In prepareforsegue how datas are passed by using arguments在 prepareforsegue 中如何使用参数传递数据
【发布时间】:2013-07-26 17:36:10
【问题描述】:

在情节提要中,我想将数据从一个视图控制器传递到另一个视图控制器,但只有属性是共享的,但是我如何通过使用参数(方法)来共享数据。在下面我尝试过这样

Tableview 选择方法

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [self performSegueWithIdentifier:@"ASEventDetail" sender:self];
}

在为 segue 做准备时,我在方法“[vc loadDict:[eventArr objectAtIndex:0]]”中传递参数值

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    // Make sure your segue name in storyboard is the same as this line
    if ([[segue identifier] isEqualToString:@"ASEventDetail"]){
        // Get reference to the destination view controller
        ASEventDetail *vc = [segue destinationViewController];        
        // Pass any objects to the view controller here, like...
        [vc loadDict:[eventArr objectAtIndex:self.view.tag]];
    }
}

能否请任何人帮助我使用情节提要中的方法将数据从一个传递到另一个。

【问题讨论】:

  • 我想loadDict是你自己的方法吗?这里有什么问题?您还可以通过目标视图控制器上的属性传递数据。
  • loadDict 是我自己的方法,我的问题是通过属性传递数据时没有问题,但是在这里我想通过方法来传递数据。我无法传递数据,因为首先是我的方法被调用,然后调用 viewdidload 就是我的问题
  • 不知道我是否理解您的问题,但如果您使用 popover,请查看我的问题:stackoverflow.com/questions/8838160/…
  • 你是对的,那是我的问题@Leonard 你能帮我找到解决办法吗

标签: ios objective-c storyboard segue


【解决方案1】:

您可以通过属性或方法传入数据(只要该方法正在存储数据)。但是,您不应该在 loadDict 方法中更新 UI。

相反,将数据保存在属性或实例变量中,然后在目标控制器上的viewWillAppear 中,根据数据更新 UI。

【讨论】:

    【解决方案2】:

    在目标视图控制器上设置您的自定义属性,使用此方法在所有视图控制器中传递属性

     ASEventDetail *vc = [segue destinationViewController]; 
    vc.someobject=[eventArr objectAtIndex:self.view.tag];
    

    参考可以参考Pass Data Between View Controllers

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多