我正在尝试将我的 Dropbox 文件加载到 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