iOS 判断文件下载的文件类型
来源:互联网 发布:plc控制电机正反转编程 编辑:程序博客网 时间:2024/05/18 00:54
1.把下载的文件放进数组中
2.在数据源方法中下:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return _cellDataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *identifier = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
}
if (_cellDataArray)
{
NSString *filePath = _cellDataArray[indexPath.row];
CFStringRef UTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)[filePath pathExtension], NULL);
CFStringRef MIMEType = UTTypeCopyPreferredTagWithClass (UTI, kUTTagClassMIMEType);
NSString *cbFileType = (__bridge NSString *)MIMEType;
//图片.txt.doc.exel.ppt等类型判断
if ([cbFileType isEqualToString:@"image/png"] || [cbFileType isEqualToString:@"image/jpeg"])
{
//cell图片显示
cell.imageView.image = [UIImage imageNamed:@"000"];
}else if([cbFileType isEqualToString:@"text/plain"] ||[cbFileType isEqualToString:@"application/vnd.ms-excel"] ||[cbFileType isEqualToString:@"application/vnd.ms-powerpoint"]||[cbFileType isEqualToString:@"application/msword"]||[cbFileType isEqualToString:@"application/vnd.openxmlformats-officedocument.wordprocessingml.document"])
{
//cell图片显示
cell.imageView.image = [UIImage imageNamed:@"000"];
}
else
{ //cell图片显示
cell.imageView.image = [UIImage imageNamed:@"000"];
}
//所有的子文件名字
cell.textLabel.text = _cellDataArray[indexPath.row];
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *filePath = _cellDataArray[indexPath.row];
//类型判断
CFStringRef UTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)[filePath pathExtension], NULL);
CFStringRef MIMEType = UTTypeCopyPreferredTagWithClass (UTI, kUTTagClassMIMEType);
//子控制器
CBfile *fileController = [[CBfile alloc]init];
fileController.cbFileType = (__bridge NSString *)MIMEType;
NSString *abs = [[self.basepath stringByAppendingString:@"\/"] stringByAppendingString:_cellDataArray[indexPath.row]];
fileController.nextAppearFilePath = abs;
//push出来控制器
[self.navigationController pushViewController:fileController animated:YES];
}
- (void)viewDidLoad
{
[super viewDidLoad];
//png,jpg
if ([self.cbFileType isEqualToString:@"image/png"]|| [self.cbFileType isEqualToString:@"image/jpeg"]) {
[self appearImageView];
//txt
}else if([self.cbFileType isEqualToString:@"text/plain"]) {
[self appearWebView];
//word
}else if([self.cbFileType isEqualToString:@"application/msword"]||[self.cbFileType isEqualToString:@"application/vnd.openxmlformats-officedocument.wordprocessingml.document"]) {
[self appearLableView];
//exel
}else if([self.cbFileType isEqualToString:@"application/vnd.ms-excel"]) {
[self appearExel];
//ppt
}else if([self.cbFileType isEqualToString:@"application/vnd.ms-powerpoint"]) {
[self appearPpt];
//other
}else {
[self appearOther];
}
}
- iOS 判断文件下载的文件类型
- 下载的文件没有文件类型
- 文件二进制头与文件类型的判断
- 根据文件的头信息判断文件类型
- php上传文件文件类型的判断方法
- 文件二进制头与文件类型的判断
- 文件二进制头与文件类型的判断
- IOS判断文件类型
- IOS判断文件类型
- Linux文件类型的判断
- 文件类型的判断
- 利用文件头判断文件类型
- 根据文件头判断文件类型
- 根据文件头判断文件类型
- 上传文件的文件类型及大小的判断
- 文件头信息中用来判断文件类型的16进制串
- PHP根据文件头信息准确判断上传的文件类型
- php 读取文件头判断文件类型的代码
- Android权限之packages.xml解析
- 聊聊高并发(七)实现几种自旋锁(二)
- Android recovery UI实现分析
- Launcher源码学习记录(一)
- Java数字的格式化
- iOS 判断文件下载的文件类型
- 准备开始写博客了
- 控制台编程笔记
- 开发者、设计师和管理人员必备的20款在线工具(上)
- redo log移动位置并重新命名步骤
- Android中的UID、GID与应用安全
- android绘制文本
- linux安装mongodb tar 加入服务并开机启动
- VLC搭建RTSP服务器的过程