【问题标题】:How to pass data from one ViewController to another after using Segue?使用 Segue 后如何将数据从一个 ViewController 传递到另一个?
【发布时间】:2018-10-15 00:16:04
【问题描述】:

我在第二个 viewController 中使用 Segue 从一个 ViewController 转到另一个 ViewController 有一个 UITableView。现在,我想从第二个 ViewController 的 didSelected 方法推送到另一个 viewController。

用于 Segue 的代码:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

self.view.backgroundColor = [UIColor clearColor];
self.modalPresentationStyle = UIModalPresentationOverCurrentContext;

SearchVC *svc = segue.destinationViewController;
self.providesPresentationContextTransitionStyle = YES;
self.definesPresentationContext = YES;
}

在按钮操作下:

-(void) searchButtonClicked:(id)sender {
[self performSegueWithIdentifier:@"search" sender:nil];
}

这里出现了主要问题,无法使用以下代码导航:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  PackageListVC *pdvc = (PackageListVC *)[self.storyboard instantiateViewControllerWithIdentifier:@"PackageListVC"];

  pdvc.strServiceProviderId = [[[arrSearch objectAtIndex:indexPath.row] objectForKey:@"ServiceProviderId"] stringValue];
  pdvc.strCategoryId = [[[arrSearch objectAtIndex:indexPath.row] objectForKey:@"CategoryId"] stringValue];
  pdvc.strSubCategoryId = [[[arrSearch objectAtIndex:indexPath.row] objectForKey:@"SubCategoryId"] stringValue];
  pdvc.strTitle = [[arrSearch objectAtIndex:indexPath.row] objectForKey:@"CompanyName"];

  [self.navigationController pushViewController:pdvc animated:YES];
}

【问题讨论】:

标签: ios objective-c uitableview uinavigationcontroller uistoryboardsegue


【解决方案1】:

您在prepareForSegue 方法中执行此操作。

在你声明 svc (SearchVC *svc = segue.destinationViewController;) 的地方你可以这样说:

 svc.variable = 1;

【讨论】:

    猜你喜欢
    • 2013-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多