如何打开一个文件浏览器,并选择在IOS .pdf文件 [英] How to open a file browser and select a .pdf file in ios

查看:430
本文介绍了如何打开一个文件浏览器,并选择在IOS .pdf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何打开一个文件浏览器,当按钮被窃听在我iphone.It应用程序来显示文件,扩展名为.pdf format.And它必须保存到本地数据库。例如,如果我们要发送电子邮件至XYZ,我们重视一些文件,如果我们要发送文件。如果我们点击附加文件按钮,它会显示文件explorer.In相同的方式,文件浏览器,如果有用户点击一个被打开在iphone.Please按钮帮我出这一点。

How to open a file browser when a button is tapped in my application in iphone.It has to show the files with an extension of .pdf format.And it has to be saved to a local database.For example,if we want to send an email to xyz,we attach some files if we want to send files.If we click attach a file button,it will show the file explorer.In the same manner the file explorer has to be opened if the user clicks a button in iphone.Please help me out of this.

推荐答案

我与我的iPhone应用程序类似的东西。由于IOS没有(我认为)的文件浏览器,你在大温线,只允许当他单击附加文件,我打开一个UIPopoverController,我告诉他所有扩展名为我的文件,使用应用程序的文档文件夹想。在我的情况是该.csv文件,我用这个算法:

I did something similar with my IOS application. As IOS don't have(I think) a file browser and you are, in big therms, only allowed to use your application Documents folder when he clicks to attach file I open a UIPopoverController and I show him all the files with the extension I want. In my case was the .csv files and I use this algorithm:

        _data= [[NSMutableArray alloc] init];
    NSString *documentsPath= [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    NSError *error;
    NSArray* files= [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsPath error:&error];
    NSRange range;

    for (NSString* file in files) {
        range = [file rangeOfString:@".csv" 
                            options:NSCaseInsensitiveSearch];
        if (range.location!= NSNotFound) {
            [_data addObject:file];
        }
    }

在哪里_data是一个数组我在使用的tableView知道所有的CSV文件,我有。如果你想这样做,作为一个文件浏览器显示目录,让用户看到文件进入目录递归。我的表数据源:

Where _data is an array I use in my tableView to know all csv files I have. If you want to do that as a file browser show the directories to and let the user see the files into the directories recursively. My table dataSource:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [_data count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell==nil) {
    cell= [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
}    
cell.textLabel.text=[_data objectAtIndex:indexPath.row];    
return cell;
}

我希望它可以帮助你。

I hope it helps you

这篇关于如何打开一个文件浏览器,并选择在IOS .pdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆