【发布时间】:2012-03-02 19:25:18
【问题描述】:
我有一个 UIViewController“PdfViewController”,它的视图包含一个 UIScrollView,它包含一个由情节提要设计的 UIWebView。我在 Xcode 4.2 中使用带有 ARC 的故事板。 如果我将 PdfViewController 作为初始 ViewController 启动,则 webview 将按预期显示。 我希望 PdfViewController 从 PDF 列表中显示 PDF。所以我制作了一个 NavigationController,其中包含一个带有文档标题的 TableViewController。 如果我尝试通过“tableView didSelectRowAtIndexPath”显示 PdfViewController,则视图将保持黑色并且不会加载所选文档。 Xcode 没有错误消息。
PdfViewController 中的 viewDidLoad 和 viewWillAppear 被调用。
这里是PdfViewController的初始化
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
PdfViewController *pdfViewController = [[PdfViewController alloc]init];
[pdfViewController setFileName:@"test"];
[self.navigationController pushViewController:pdfViewController animated:YES];
}
-看来,问题在于 PdfViewController 不会自行加载相应的笔尖。 如果我从 TableViewCell 中创建一个序列,则 PdfViewController 会正确加载。
我把代码改成:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.navigationController.viewControllers.lastObject setFileName:@"test"];
}
这里唯一要知道的是viewDidLoad和viewWillAppear是在tableView didSelectRowAtIndexPath执行之前调用的,所以PDF必须在viewDidAppear中加载。
【问题讨论】:
-
没有什么是明显不正确的。您能否发布您用来查看
PdfViewController在初始视图时正确显示的工作代码?
标签: objective-c uiwebview navigationcontroller