我有打印出不同的PDF的代码,这取决于选择哪个表格行。我使用StoryBoards开发了这个功能并使用Segues。我从prepareForSegue开始,并转向执行SegueWithIdentifier,因为我需要从一个TableViewController进行几次循环。我可以:(1)获取传递的行值(整数),但是,webView pdf加载不起作用(使用vc2代码),或者(2)我可以加载webView pdf,但不传递行值performSegueWithIndentifier(所以只有行= 0 pdf加载)。经过一整周的研究和尝试,我仍然困惑不解。这里有一些基本的东西我不明白。请帮忙。多个Segue和数字传递不起作用
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]];
这不是我清楚你在做什么试图做,但在didSelectRowAtIndexPath中执行SegueWithIdentifier和pushViewController很可能是错误的。 “showView1”和“showView2”在哪里(哪些视图控制器)? – rdelmar 2013-05-07 01:41:04
谢谢。没有一起使用pSWI和pVC。分别尝试了两种方法。每个人都有缺陷。 pVC传递了行值并更正了pdf名称,但webView不会加载PDF。没有使用pSWI传输行值。每次都是一样的pdf。 ShowView1是SecondViewController的一部分,它将显示不同的PDF,具体取决于选择FirstViewController的行值(为什么我需要传递的行值)。我放入ShowView2是因为我最终会添加ThirdViewController(现在不是)。任何帮助将不胜感激。 – user2353906 2013-05-07 04:16:06