Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/95.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 多段和数字传递不起作用_Ios - Fatal编程技术网

Ios 多段和数字传递不起作用

Ios 多段和数字传递不起作用,ios,Ios,我有一些代码,可以根据选择的表行打印出不同的PDF。我使用故事板和Segues开发了这个。我从prepareForSegue开始,然后转到performSegueWithIdentifier,因为我需要从一个TableViewController中获得多个分段。我可以:(1)获得传递的行值(整数),但webView pdf加载不起作用(使用vc2代码),或者(2)我可以加载webView pdf,但不能使用PerformsgueWithIdentifier传递行值(因此只有行=0 pdf加载)。

我有一些代码,可以根据选择的表行打印出不同的PDF。我使用故事板和Segues开发了这个。我从prepareForSegue开始,然后转到performSegueWithIdentifier,因为我需要从一个TableViewController中获得多个分段。我可以:(1)获得传递的行值(整数),但webView pdf加载不起作用(使用vc2代码),或者(2)我可以加载webView pdf,但不能使用PerformsgueWithIdentifier传递行值(因此只有行=0 pdf加载)。经过整整一周的研究和尝试,我仍然感到困惑。这里有一些基本的东西我不明白。请帮忙

FirstViewController

-   (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

NSIndexPath *myIndexPath = [self.tableView indexPathForSelectedRow];
    int row = [myIndexPath row];

if (row == 0){
    [self performSegueWithIdentifier:@"showView1" sender:self];}

    else if (row == 1){
        [self performSegueWithIdentifier:@"showView1" sender:self];}

    else if (row == 2){
        [self performSegueWithIdentifier:@"showView2" sender:self];}

SecondViewController *vc2 = [[SecondViewController alloc]init];
vc2.row = row;
[self.navigationController pushViewController:vc2 animated:YES];




SecondViewController

if (row == 0) {
        NSString *path = [[NSBundle mainBundle] pathForResource:@"cover" ofType:@"pdf"];
        pdfUrl = [NSURL fileURLWithPath:path];
        NSLog(@"in SecondView Controller path =: %@", pdfUrl);}

    else if(row == 1){
        NSString *path = [[NSBundle mainBundle] pathForResource:@"welcome" ofType:@"pdf"];
        pdfUrl = [NSURL fileURLWithPath:path];
        NSLog(@"in SecondView Controller path =: %@", pdfUrl);}

    [webView loadRequest:[NSURLRequest requestWithURL:pdfUrl]];

您需要将prepareForSegue与performSegueWithIdentifier一起使用。因此,在performsguewithidentifier:sender:method中,将选定的indexPath作为发送方传递:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

   if (indexPath.row < 2) [self performSegueWithIdentifier:@"showView1" sender:indexPath];
   if (indexPath.row == 2) [self performSegueWithIdentifier:@"showView2" sender:indexPath];
}

我不清楚您想做什么,但在didSelectRowAtIndexPath中使用IDENTIFIER和pushViewController执行这两项操作很可能是错误的。“showView1”和“showView2”将把您带到哪里(哪个视图控制器)?谢谢。没有同时使用pSWI和pVC。分别尝试了两种方法。每个人都有缺点。pVC传递了行值和正确的pdf名称,但webView不会加载pdf。不使用pSWI进行行值传输。所以每次都是相同的pdf。ShowView1是SecondViewController的一个分段,它将根据FirstViewController选择的行值显示不同的PDF(为什么需要传递行值)。我之所以加入ShowView2,是因为我最终将添加第三个ViewController(只是不是现在)。任何帮助都将不胜感激。谢谢!非常感谢。这非常有效,教会了我很多。这是我第一次使用堆栈溢出。我应该投票还是做评分?您在我的书中获得AAA++@user2353906,您可以向上投票(如果允许的话,我不知道是否需要一定数量的声誉点数),您可以点击大空心箭头接受答案。可以。再次感谢你。
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(NSIndexPath *)selectedIndexPath {
    if ([segue.identifier isEqualToString:@"showView1"]) {
        SecondViewController *vc2 = segue.destinationViewController;
        vc2.row = selectedIndexPath.row;
    }else if ([segue.identifier isEqualToString:@"showView2"]) {
        //do something else
    }
}