2012-08-17 2 views
2

보관 용 파일을 UITableView에로드하려고하는데 표시되지 않습니다. dropbox.com에 내 앱을 등록하고 내 앱에서 세션 대리인을 구현하는 모든 단계를 수행했습니다. 여기 내 코드는 누구나 저에게 뭐가 잘못 됐는지 말해 줄 수 있습니까? 임 꽤 확신 내가 모든 것을 올바르게 선언했지만 문제는 찾을 수 없습니다. 또한 NSLog를 추가하고 파일을 기록하기 때문에 연결 문제가 아니라는 것을 알고 있습니다.보관 용 파일을 UITableView에 추가

#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 
+0

당신은 당신이 파일을 기록했다? dropBoxURL을 로그하여 로그에 아무것도 없는지 확인 했습니까? 오류 메시지에서 배열이 비어있는 것으로 나타납니다. – rdelmar

+0

@rdelmar 안녕하세요, 내가 배열에 추가하기 전에 바로 파일을 기록 : NSLog (@ "% @", file.filename); [dropboxURLs addObject : file.filename]; – Cristian

+0

numberOfRowsInSection 메서드에서 dropboxURLs.count를 반환하여 반환하는 내용을 확인하십시오. – rdelmar

답변

0

dropboxURLs 배열에 항목을 추가 한 후 테이블보기를 다시로드하십시오.

[self.tableView reloadData]; 
+0

안녕하세요. 2012-08-17 11 : 55 : 46.938 공유 Me [5987 : 907] *** 잡히지 않은 예외로 인해 앱 종료 중 'NSRangeException'이유 : '*** - [__ NSArrayM objectAtIndex :] : 빈 배열 범위를 넘는 인덱스 0' *** 먼저 던져 호출 스택 : (0x3acfe6c3 0x34d7e97f 0x3ac4a055 0x60065 0x39d4ab81 0x39d2f93b 0x39d46e17 0x39d02f2b 0x39bdde9b 0x39bdda39 0x39bde975 0x39bde353 0x39bde161 0x39bddfc1 0x3acd3aed 0x3acd1de1 0x3acd2137 0x3ac4539d 0x3ac45229 0x3780231b 0x39d538f9 0x59ce9 0x352bab20) libC++ abi.dylib : 예외를 던지기 위해 종료 – Cristian

0

즉시 addObject 호출 한 후이 같은 시도 :

+0

안녕하세요, 내가 이것을 추가하면 안녕하세요 : 2012-08-17 11 : 55 : 46.938 Share Me [5987 : 907] *** 캐치되지 않은 예외 'NSRangeException', 이유로 응용 프로그램 종료 : '*** - [__ NSArrayM obj ectAtIndex :] : 빈 배열에 대한 경계 '를 넘어 인덱스 0 *** 먼저 던져 호출 스택 : (0x3acfe6c3 0x34d7e97f 0x3ac4a055 0x60065 0x39d4ab81 0x39d2f93b 0x39d46e17 0x39d02f2b 0x39bdde9b 0x39bdda39 0x39bde975 0x39bde353 0x39bde161 0x39bddfc1 0x3acd3aed 0x3acd1de1 0x3acd2137 0x3ac4539d 0x3ac45229 0x3780231b 0x39d538f9 0x59ce9 0x352bab20) libc의 + + abi.dylib : 예외를 발생시키는 호출 종료 – Cristian

0
-(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]; 
      } 
     } 
    } 
    [self. tableView reloadData]; 
    } 

[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationFade]; 
자체에 jQuery과의 위임 및 데이터 소스를 설정하는 것을 잊지 마십시오.

0
  • 우리 메타 후
  • 가로드 DropBoxRoot
  • 로부터 데이터를로드 할 수있는 상기의 tableview
  • (보이드)의 viewDidLoad {
    를 다시 [슈퍼의 viewDidLoad];
    dropboxURLs = [[NSMutableArray alloc] init];
    [self loadData]; 당신이 그 짓을 한거야 -
    }는
-(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]; 
} 
관련 문제