0

iOS で BoxSDK を使用しようとしていますが、現在のフォルダー/ファイルの親ディレクトリを読み込む必要があります。BoxItems の配列があり、BoxItem.parent を取得しようとしましたが、常に null です。pathCollection についても同様です。

アプリの読み込み時に、ModelID と名前を使用して最後のディレクトリを読み込みます。この BoxItem の親ディレクトリを取得するにはどうすればよいですか?

編集: リクエストから一連の BoxModels が返ってきたと思います。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];

そして、tableView をロードするために使用できる BoxItems でいっぱいの BoxCollection を取得します。サンプルアプリ外です。

次に、BoxItems を取得したばかりの folderID の親を取得したいので、これを使用します。

- (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 に親メソッドがあると記載されていますが、それを取得するには、BoxFolder オブジェクトを作成し、それを BoxItem.parent と等しくなるように設定する必要があります。

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

これにより、参照する親オブジェクトが取得されます。

于 2014-08-04T14:10:27.547 に答える