Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
搜索xcode谷歌硬盘文件内的文件/文件夹_Xcode_Google Drive Api_Tableview_Uisearchdisplaycontroller - Fatal编程技术网

搜索xcode谷歌硬盘文件内的文件/文件夹

搜索xcode谷歌硬盘文件内的文件/文件夹,xcode,google-drive-api,tableview,uisearchdisplaycontroller,Xcode,Google Drive Api,Tableview,Uisearchdisplaycontroller,我正在尝试在iOS中制作google drive文件管理应用程序。我被卡住了,因为我想用任何关键字搜索所有文件,它应该是“显示文件和文件夹”。使用此代码获取所有文件和文件夹。但如果搜索某个内容,请只搜索当前文件。您能建议我如何获取子文件和文件夹吗,因为它只显示一个级别而不显示其他级别。 -(无效)getGDriveFilesAndFolders { GTLQueryDrive*query=[GTLQueryDrive queryForFilesList]; if([self.strPath le

我正在尝试在iOS中制作google drive文件管理应用程序。我被卡住了,因为我想用任何关键字搜索所有文件,它应该是“显示文件和文件夹”。使用此代码获取所有文件和文件夹。但如果搜索某个内容,请只搜索当前文件。您能建议我如何获取子文件和文件夹吗,因为它只显示一个级别而不显示其他级别。
-(无效)getGDriveFilesAndFolders {

GTLQueryDrive*query=[GTLQueryDrive queryForFilesList];
if([self.strPath length]==0)
{
query.q=@“父目录中的根目录”;
}否则{
NSString*queryString=[NSString stringWithFormat:@“%@”在父级中,self.strPath];
q=queryString;
}
[GoogleDriveViewController.driveService执行任务:查询完成处理程序:^(GTLServiceTicket*票证,GTLDriveFileList*文件,N错误*错误)
{
如果(错误==nil)
{
[marrviles removeAllObjects];
NSDateFormatter*dateFormatter=[[NSDateFormatter alloc]init];
[日期格式化程序setDateFormat:@“yyyy-MM-dd hh:MM:ss”];
对于(int i=0;i<[files items]。计数;i++)
{
GTLDriveFile*driveFile=(GTLDriveFile*)[files itemAtIndex:i];
if([driveFile.mimeType isEqualToString:@“application/vnd.google apps.folder”])
{
如果([driveFile.explicitlyTrashed intValue]!=1)
{
NSString*fileName=driveFile.title;
NSMutableDictionary*dict=[NSMutableDictionary];
[dict setValue:fileName forKey:[NSString stringWithFormat:@“Folder”];
[dict setValue:driveFile.identifier forKey:@“objectId”];
[对象:dict];
}
}
否则{
如果([driveFile.explicitlyTrashed intValue]!=1)
{
NSString*fileName=driveFile.title;
NSMutableDictionary*dict=[NSMutableDictionary];
[dict setValue:fileName forKey:[NSString stringWithFormat:@“File”];
long long int sizeData=[driveFile.fileSize intValue];
NSString*stringSize=[FileSizeClass stringSizeForFileWithBytes:[NSNumber numberWithLongLong:sizeData]];
GTLDateTime*modificationDate=(GTLDateTime*)driveFile.modifiedDate;
NSDate*日期=[修改日期];
NSString*dateString=[dateFormatter stringFromDate:date];
dateString=[dateString createdTimeString];
NSString*stringInfo=[NSString stringWithFormat:@“%@%@”,stringSize,dateString];
[dict setValue:stringInfo-forKey:[NSString stringWithFormat:@“Size”];
[dict setValue:driveFile.identifier forKey:@“objectId”];
[dict setValue:driveFile.downloadUrl forKey:@“downloadUrl”];
[dict setValue:driveFile.fileSize-forKey:@“fileSize”];
if(driveFile.webContentLink)
{
[dict setValue:driveFile.webContentLink-forKey:@“webContentLink”];
}
[对象:dict];
}
}
}
[tblGoogleDrive重载数据];
}否则{
UIAlertView*alertView=[[UIAlertView alloc]initWithTitle:NSLocalizedString(@“Message”,nil)Message:[错误localizedDescription]委托:nil CancelButtonTile:@“Ok”其他ButtonTiles:nil,nil];
[警报视图显示];
}
[MBProgressHUD hidealhudsforview:self.view动画:是];
}];

}

在父文件夹中使用类似“文件夹id”的搜索查询仅搜索该文件夹的直接子文件夹,而不在子文件夹中。没有内置的方法来搜索子文件夹,但您可以创建一个复合查询,在其中显式搜索每个子文件夹,例如父文件夹中的“文件夹”或父文件夹中的“子文件夹1”…

不清楚您要的是什么。你想要什么,你的代码现在在做什么?这段代码只是将文件和文件夹列表到tableview中。使用搜索显示控制器,它只搜索tableview中的当前文件和文件夹。我必须在文件中显示文件。e、 g folder1->f1.txt,f2.txt。问题是当您搜索某个内容时,仅显示当前文件或文件夹。搜索f1时,它将显示“未找到”。这意味着此代码适用于当前文件和文件夹,而不适用于子文件和子文件夹。那么,我应该怎么做才能在任何地方得到任何文件呢?
GTLQueryDrive *query = [GTLQueryDrive queryForFilesList];
if ([self.strPath length] == 0)
{
    query.q = @"'root' in parents";
}else{
    NSString *queryString = [NSString stringWithFormat:@"'%@' in parents",self.strPath];
    query.q=queryString;
}

[GoogleDriveViewController.driveService executeQuery:query completionHandler:^(GTLServiceTicket *ticket,GTLDriveFileList *files,NSError *error)
 {
     if (error == nil)
     {
         [marrFiles removeAllObjects];

         NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
         [dateFormatter setDateFormat:@"yyyy-MM-dd hh:mm:ss"];

         for(int i = 0; i < [files items].count; i++)
         {
             GTLDriveFile *driveFile = (GTLDriveFile*)[files itemAtIndex:i];
             if([driveFile.mimeType isEqualToString:@"application/vnd.google-apps.folder"])
             {
                 if([driveFile.explicitlyTrashed intValue]!=1)
                 {
                     NSString *fileName = driveFile.title;
                     NSMutableDictionary *dict = [NSMutableDictionary dictionary];
                     [dict setValue:fileName forKey:[NSString stringWithFormat:@"Folder"]];
                     [dict setValue:driveFile.identifier forKey:@"objectId"];
                     [marrFiles addObject:dict];
                 }
             }
             else{
                 if([driveFile.explicitlyTrashed intValue] != 1)
                 {
                     NSString *fileName = driveFile.title;
                     NSMutableDictionary *dict = [NSMutableDictionary dictionary];
                     [dict setValue:fileName forKey:[NSString stringWithFormat:@"File"]];
                     long long int sizeData = [driveFile.fileSize intValue];
                     NSString *stringSize = [FileSizeClass stringSizeForFileWithBytes:[NSNumber numberWithLongLong:sizeData]];
                     GTLDateTime *modificationDate = (GTLDateTime*)driveFile.modifiedDate;
                     NSDate *date = [modificationDate date];
                     NSString *dateString = [dateFormatter stringFromDate:date];
                     dateString = [dateString createdTimeString];
                     NSString *stringInfo = [NSString stringWithFormat:@"%@ %@",stringSize,dateString];
                     [dict setValue:stringInfo forKey:[NSString stringWithFormat:@"Size"]];
                     [dict setValue:driveFile.identifier forKey:@"objectId"];
                     [dict setValue:driveFile.downloadUrl forKey:@"downloadUrl"];
                     [dict setValue:driveFile.fileSize forKey:@"FileSize"];

                     if(driveFile.webContentLink)
                     {
                         [dict setValue:driveFile.webContentLink forKey:@"webContentLink"];
                     }
                     [marrFiles addObject:dict];
                 }
             }
         }
         [tblGoogleDrive reloadData];
     } else {
         UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:NSLocalizedString(@"Message",nil) message:[error localizedDescription] delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
         [alertView show];
     }
     [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
 }];