【问题标题】:How to open files in a UIWebView?如何在 UIWebView 中打开文件?
【发布时间】:2013-06-12 16:53:17
【问题描述】:

我只是为 iOS 制作了一个文件浏览器,我只需要知道如何在 UIWebview 中打开任何类型的文件。我认为 webview 可以打开任何类型的文件,那是因为我选择使用 UIWebView 直接在应用程序中查看文件。现在我的问题。

如何以编程方式切换到同一 UIStoryBoard 中的 UIViewController 并显示文件?文件 URL 存储在一个名为 path 的字符串中。

我就是这样,我只需要添加文件查看器。

有人可以帮我吗?

【问题讨论】:

  • 为什么不使用文件管理器?而不是 UIWebView..
  • 我不知道这个
  • 了解 NSFileManager...
  • 好的,谢谢。但是如何使用 NSFileManager 来显示文件呢?我用它在表格视图中显示文件路径

标签: ios uiviewcontroller webview uistoryboard


【解决方案1】:
-(void) displayFile:(NSString*)fileName
{
  NSError *error = nil;
  NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,   NSUserDomainMask, YES) objectAtIndex:0]; 
  TO get the filename
  NSString *folderPath = [documentsDirectory stringByAppendingPathComponent:fileName];  

  if (![[NSFileManager defaultManager] fileExistsAtPath:folderPath])  //Optionally check if   folder already hasn't existed.
  {
   // do something
  }
} 

希望对你有帮助...

【讨论】:

  • 有点,我需要知道如何从我在上面的帖子中向您展示的表格视图切换到位于 UIViewController 中的 UIWebView。我喜欢制作 pushViewController 动画。
  • 使用 didSelectRowAtIndexPath 方法... -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  • 这个我已经有了,我只需要知道切换到另一个UIViewController的命令
  • 方法内部,使用[self pushViewController:otherViewController]
  • 抱歉,Tableview 和他的其他 UIViewController 使用的是相同的 ViewController 文件。
猜你喜欢
  • 2012-06-23
  • 1970-01-01
  • 1970-01-01
  • 2015-05-04
  • 1970-01-01
  • 1970-01-01
  • 2011-11-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多