0

我正在尝试在 iOS 上使用 BoxSDK,我需要加载当前文件夹/文件的父目录。我有一个 BoxItems 数组,我尝试获取 BoxItem.parent 并且它始终为空。pathCollection 也是如此。

当应用程序加载时,我使用 ModelID 和名称加载最后一个目录。如何获取此 BoxItem 的父目录?

编辑:我想我从我的请求中得到了一堆 BoxModel。如何获取携带 ParentID 的 BoxItems?

这是我的代码:

- (void)fetchFolderItemsWithFolderID:(NSString *)folderID name:(NSString *)name
{
    _folderListArray = [[NSMutableArray alloc]init];
    BoxCollectionBlock success = ^(BoxCollection *collection)
    {
        //_folderListArray = [[NSMutableArray alloc]init];
        for (NSUInteger i = 0; i < collection.numberOfEntries; i++)
        {
            [_folderListArray addObject:[collection modelAtIndex:i]];
        }
        dispatch_sync(dispatch_get_main_queue(), ^{
            [self fetchFolderInfoWithID:folderID];
            [self.tableView reloadData];
            [self.refreshControl endRefreshing];
        });
    };
    BoxAPIJSONFailureBlock failure = ^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, NSDictionary *JSONDictionary)
    {
        NSLog(@"folder items error: %@", error);
    };
    [[BoxSDK sharedSDK].foldersManager folderItemsWithID:folderID requestBuilder:nil success:success failure:failure];

我得到了一个 BoxCollection,里面装满了可以用来加载我的 tableView 的 BoxItem。这不在示例应用程序中。

然后我想获取我刚刚从中获得 BoxItems 的那个文件夹 ID 的父级,所以我使用这个:

- (void)fetchFolderInfoWithID:(NSString *)folderID
{
    BoxFolderBlock success = ^(BoxFolder *folder)
    {
        //trying to print parent
        NSLog(@"Parent: %@", folder.pathCollection);
    NSLog(@"Parent: %@", folder.parent);
        dispatch_sync(dispatch_get_main_queue(), ^{
            NSLog(@"Parent: %@", folder.parent);
        });
    };
    BoxAPIJSONFailureBlock failure = ^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, NSDictionary *JSONDictionary)
    {
        NSLog(@"folder items error: %@", error);
    };
    BoxFoldersRequestBuilder *itemBldr = [[BoxFoldersRequestBuilder alloc]initWithQueryStringParameters:@{ @"fields" : @"name,type,id,size,modified_at,created_by,parent,path_collection" }];
    [[BoxSDK sharedSDK].foldersManager folderInfoWithID:folderID requestBuilder:itemBldr success:success failure:failure];
}
4

1 回答 1

0

所以我终于想通了。我从 Box 查询中得到了一堆 BoxItems。现在文档说 BoxItem 有一个 parent 方法,但要获得它,您需要创建一个 BoxFolder 对象并将其设置为等于 BoxItem.parent。

BoxItem *item = <item returned from query>;
BoxFolder *folder = item.parent;
NSString *paretnModelID = folder.modalID;

这将使您获得要引用的父对象。

于 2014-08-04T14:10:27.547 回答