2

ドロップボックス ファイルを UITableView に読み込もうとしていますが、表示されません。アプリを dropbox.com に登録し、アプリにセッション デリゲートを実装するまで、すべての手順を実行しました。これが私のコードです。誰でも何が問題なのか教えてください。私はすべてを正しく宣言したと確信していますが、問題を見つけることができないようです。また、NSLogを追加してファイルをログに記録したため、接続の問題ではないこともわかっています。

#import <UIKit/UIKit.h>
#import <DropboxSDK/DropboxSDK.h>

@interface testViewController : UITableViewController <DBRestClientDelegate>
{
    DBRestClient *restClient;
    NSMutableArray *dropboxURLs;
}
@end

#import "testViewController.h"

@interface testViewController ()

@end




@implementation testViewController

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (DBRestClient *)restClient {
    if (!restClient) {
        restClient =
        [[DBRestClient alloc] initWithSession:[DBSession sharedSession]];
        restClient.delegate = self;
    }
    return restClient;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    dropboxURLs = [[NSMutableArray alloc] init];
    [[self restClient] loadMetadata:@"/"];
}

- (void)restClient:(DBRestClient *)client loadedMetadata:(DBMetadata *)metadata {
    if (metadata.isDirectory) {
        for (DBMetadata *file in metadata.contents) {
            if (!file.isDirectory)
            {
                NSLog(@"%@", file.filename);
                [dropboxURLs addObject:file.filename];
            }
        }
    }
}

- (void)restClient:(DBRestClient *)client
loadMetadataFailedWithError:(NSError *)error {

    NSLog(@"Error loading metadata: %@", error);
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return dropboxURLs.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"FileCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if(cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    cell.textLabel.text = [dropboxURLs objectAtIndex:indexPath.row];

    return cell;
}

@end
4

4 に答える 4

0

addObject 呼び出しの直後に次のようなことを試してください。

[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationFade];
于 2012-08-17T15:50:00.893 に答える
0
  • DropBoxRoot からデータをロードする必要があります
  • メタデータが読み込まれた後、テーブルビューを再読み込みします
  • (void)viewDidLoad{
    [スーパービューDidLoad];
    dropboxURLs = [[NSMutableArray alloc] init];
    [自己ロードデータ];
    }
-(void) loadData{
if ([DBSession sharedSession].root == kDBRootDropbox) {
    photosRoot = @"/";//can specify any folder like /Photos,/Public etc
}
[self.restClient loadMetadata:photosRoot withHash:photosHash];
}


- (void)restClient:(DBRestClient*)client loadedMetadata:(DBMetadata*)metadata {

photosHash = metadata.hash;

NSArray* validExtensions = [NSArray arrayWithObjects:@"jpg", @"jpeg",@"png",@"txt",@"pdf",@"doc",@"mp3",@"mp4", nil];
for (DBMetadata* child in metadata.contents) {

    NSString* extension = [[child.path pathExtension] lowercaseString];

    if (!child.isDirectory && [validExtensions indexOfObject:extension] != NSNotFound) {
        [directory addObject:child.filename];
    }else{
        [allFileAndDirectory addObject:child.filename];
    }
    [myTableView reloadData];
}
于 2014-03-28T13:03:54.700 に答える
0

dropboxURLs 配列に何かを追加した後、テーブル ビューを再読み込みします。

[self.tableView reloadData];
于 2012-08-17T15:37:14.517 に答える