gpt4 book ai didi

ios - 如何在 iOS 中打开文件浏览器并选择 .pdf 文件

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:52:39 28 4
gpt4 key购买 nike

在我的 iphone 应用程序中点击按钮时如何打开文件浏览器。它必须显示扩展名为 .pdf 格式的文件。它必须保存到本地数据库。例如,如果我们想发送电子邮件给 xyz,如果我们想发送文件,我们会附上一些文件。如果我们点击附加文件按钮,它将显示文件资源管理器。以同样的方式,如果用户单击文件资源管理器,则必须打开文件资源管理器iphone 中的按钮。请帮我解决这个问题。

最佳答案

我对我的 IOS 应用程序做了类似的事情。由于 IOS 没有(我认为)文件浏览器,而且你在大热中,只允许在他单击附加文件时使用你的应用程序文档文件夹,我打开一个 UIPopoverController 并向他展示所有扩展名为 I 的文件想。在我的例子中是 .csv 文件,我使用这个算法:

        _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 文件。如果您想将文件浏览器显示为目录,并让用户递归地查看目录中的文件。我的表格数据源:

- (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;
}

希望对你有帮助

关于ios - 如何在 iOS 中打开文件浏览器并选择 .pdf 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9922755/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com