2010-01-06 67 views
0

我在这里提出质疑:Best idea for importing text to each NavigationController View回答我关于导航控制器的旧问题!

的回答是这样的:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    PoemDetailsViewController *poemDetails = [[[PoemDetailsViewController alloc] initWithNibName:@"PoemDetailsViewController" bundle:nil] autorelease]; 
    poemDetails.poem = [poems objectAtIndex:indexPath.row]; // assuming you have a single dimension array with poems and a single table group 
    [self.navigationController pushViewController:poemDetails animated:YES]; 
} 

现在在PoemDetailsViewController我创建一个UIWebView并编写这些代码:

(我知道这个代码只显示一个我的HTML文件)

NSString *path = [[NSBundle mainBundle] pathForResource:@"fal1" ofType:@"html"]; 
NSFileHandle *readHandle = [NSFileHandle fileHandleForReadingAtPath:path]; 

NSString *htmlString = [[NSString alloc] initWithData: 
          [readHandle readDataToEndOfFile] encoding:NSUTF8StringEncoding]; 

现在我找不到任何关联此代码

poemDetails.poem = [poems objectAtIndex:indexPath.row]; 

在每个单元格上加载AnotherViewController上的诗吗?

我的意思是每个细胞都用导航控制器在其他视图上显示他们的诗。

+0

是否有一个理由,为什么你不使用'NSString.stringWithContentsOfFile:编码:错误:'? – notnoop 2010-01-06 22:26:20

+0

我有495个电池,所以他们进口plist财产! NSString * myfile = [[NSBundle mainBundle] pathForResource:@“ghazal”ofType:@“plist”]; \t ghazalList = [[NSArray alloc] initWithContentsOfFile:myfile]; 和: - (NSInteger的)的tableView:(UITableView的*)的tableView numberOfRowsInSection:(NSInteger的)部分 { \t返回ghazalList.count; } 等 (为什么评论没有代码标记!?) – Momi 2010-01-06 22:36:49

+0

@notnoop:对不起IAM新iPhone的SDK – Momi 2010-01-06 22:41:45

回答

1

在考虑中的线:

poemDetails.poem = [poems objectAtIndex:indexPath.row]; 

被简单地传递有关被选择为新的视图控制器的行(诗)的信息。

通常,“诗歌”将是一个自定义类,其中包含有关该诗的相关信息,例如其标题和HTML文件的名称,但它可能只是一个字符串(如果标题为& HTML文件名匹配)。

例如,你会在这里使用它:

NSString *path = [[NSBundle mainBundle] pathForResource:poem.filename ofType:@"html"]; 
+0

,所以我用这个: 的NSString *路径= [[一个NSBundle mainBundle] pathForResource: @“poem”ofType:@“html”]; 但不起作用 – Momi 2010-01-06 22:37:48

+0

这将(总是)创建路径字符串为“poem.html”。你希望路径是动态的(对于不同的诗而言是不同的),所以你应该像我建议的那样使用一个变量作为路径名。 – gerry3 2010-01-07 00:44:48