Iphone NSMutableArray不';不要在视图上填充';第一次露面

Iphone NSMutableArray不';不要在视图上填充';第一次露面,iphone,objective-c,cocoa-touch,Iphone,Objective C,Cocoa Touch,我正在使用Dropbox SDK填充一个数组文件路径。 但是,数组仅在我第二次打开相应视图时才填充。当我第一次打开视图时,数组是空的 有人知道这是为什么吗 提前谢谢 // DropboxFileViewController.m #import "DropboxFileViewController.h" #import "DropboxViewController.h" #import "DropboxSDK.h" #import <stdlib.h> @interface D

我正在使用Dropbox SDK填充一个数组
文件路径
。 但是,数组仅在我第二次打开相应视图时才填充。当我第一次打开视图时,数组是空的

有人知道这是为什么吗

提前谢谢

//  DropboxFileViewController.m

#import "DropboxFileViewController.h"
#import "DropboxViewController.h"
#import "DropboxSDK.h"
#import <stdlib.h>


@interface DropboxFileViewController () <DBRestClientDelegate>


@property (nonatomic, readonly) DBRestClient* restClient;

@end


@implementation DropboxFileViewController
@synthesize dropboxFileView;
@synthesize filePaths;



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

    //NSArray* validExtensions = [NSArray arrayWithObjects:@"pdf", @"docx", @"doc", nil];
    NSMutableArray* newDropboxFilePaths = [NSMutableArray new];
    for (DBMetadata* child in metadata.contents) {
        //NSString* extension = [[child.path pathExtension] lowercaseString];
        //if (!child.isDirectory && [validExtensions indexOfObject:extension] != NSNotFound) {
            [newDropboxFilePaths addObject:child.path];
        //}
    }

    [filePaths release];
    filePaths = newDropboxFilePaths;
}



/*- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization.
    }
    return self;
}*/

#pragma mark -
#pragma mark Initialization

/*
- (id)initWithStyle:(UITableViewStyle)style {
    // Override initWithStyle: if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization.
    }
    return self;
}
*/


#pragma mark -
#pragma mark View lifecycle



- (void)viewDidLoad {
    [super viewDidLoad];

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}



- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.restClient loadMetadata:@"/"];


}

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


- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [dropboxFileView reloadData];

}

/*
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
}
*/
/*
- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
}
*/
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations.
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/


#pragma mark -
#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 [filePaths count];
    //NSLog(@"deze shit wordt geinvoked vriend");

}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";

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

    // Configure the cell...


    //NSDictionary *dictionary = [listOfItems objectAtIndex:indexPath.section];

    NSUInteger row = [indexPath row];
    cell.textLabel.text = [filePaths objectAtIndex:row];
    return cell;
}


/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/


/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source.
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
    }   
}
*/


/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/


/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/


#pragma mark -
#pragma mark Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // Navigation logic may go here. Create and push another view controller.
    /*
    <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
     // ...
     // Pass the selected object to the new view controller.
    [self.navigationController pushViewController:detailViewController animated:YES];
    [detailViewController release];
    */
}


#pragma mark -
#pragma mark Memory management

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Relinquish ownership any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
    // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
    // For example: self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}


@end
//DropboxFileViewController.m
#导入“DropboxFileViewController.h”
#导入“DropboxViewController.h”
#导入“DropboxSDK.h”
#进口
@接口DropboxFileViewController()
@属性(非原子,只读)DBRestClient*restClient;
@结束
@DropboxFileViewController的实现
@综合dropboxFileView;
@综合文件路径;
-(void)restClient:(DBRestClient*)客户端加载的元数据:(DBMetadata*)元数据{
//NSArray*validExtensions=[NSArray阵列及其对象:@“pdf”@“docx”@“doc”,nil];
NSMUTABLEARRY*NewDropboxFilePath=[NSMUTABLEARRY new];
for(metadata.contents中的DBMetadata*子级){
//NSString*扩展=[[child.path pathExtension]小写字符串];
//如果(!child.isDirectory&[validexofobject:extension]!=NSNotFound){
[NewDropboxFilePath-addObject:child.path];
//}
}
[文件路径发布];
filepath=newdropboxfilepath;
}
/*-(id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil{
self=[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
如果(自我){
//自定义初始化。
}
回归自我;
}*/
#布拉格标记-
#杂注标记初始化
/*
-(id)initWithStyle:(UITableViewStyle)样式{
//Override initWithStyle:如果以编程方式创建控制器并希望执行不适合viewDidLoad的自定义。
self=[super initWithStyle:style];
如果(自我){
//自定义初始化。
}
回归自我;
}
*/
#布拉格标记-
#pragma标记视图生命周期
-(无效)viewDidLoad{
[超级视图下载];
//取消对以下行的注释,以在此视图控制器的导航栏中显示编辑按钮。
//self.navigationItem.rightBarButtonItem=self.editButtonItem;
}
-(无效)视图将显示:(BOOL)动画{
[超级视图将显示:动画];
[self.restClient loadMetadata:@/“];
}
-(DBRestClient*)restClient{
if(restClient==nil){
restClient=[[DBRestClient alloc]initWithSession:[DBSession sharedSession]];
restClient.delegate=self;
}
返回客户;
}
-(无效)视图显示:(BOOL)动画{
[超级视图显示:动画];
[dropboxFileView重新加载数据];
}
/*
-(无效)视图将消失:(BOOL)已设置动画{
[超级视图将消失:动画];
}
*/
/*
-(无效)视图消失:(BOOL)已设置动画{
[超级视窗消失:动画];
}
*/
/*
//替代以允许默认纵向方向以外的方向。
-(布尔)应自动旋转指针面定向:(UIInterfaceOrientation)interfaceOrientation{
//对于支持的方向,返回YES。
返回(interfaceOrientation==UIInterfaceOrientationGraphic);
}
*/
#布拉格标记-
#pragma标记表视图数据源
-(NSInteger)表格视图中的节数:(UITableView*)表格视图{
//返回节数。
返回1;
}
-(NSInteger)表视图:(UITableView*)表视图行数节:(NSInteger)节{
//返回节中的行数。
返回[文件路径计数];
//NSLog(@“deze shit wordt geinvoked vriend”);
}
//自定义表格视图单元格的外观。
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
静态NSString*CellIdentifier=@“Cell”;
UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
如果(单元格==nil){
cell=[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault重用标识符:CellIdentifier]自动释放];
}
//配置单元格。。。
//NSDictionary*dictionary=[ListoItems objectAtIndex:indexath.section];
NSUTEGER行=[indexPath行];
cell.textlab.text=[filepath objectAtIndex:row];
返回单元;
}
/*
//替代以支持表视图的条件编辑。
-(BOOL)tableView:(UITableView*)tableView caneditrowatinexpath:(nsindepath*)indepath{
//如果不希望指定的项可编辑,则返回“否”。
返回YES;
}
*/
/*
//替代以支持编辑表格视图。
-(void)tableView:(UITableView*)tableView提交的编辑样式:(UITableViewCellEditingStyle)行的编辑样式索引路径:(NSIndexPath*)索引路径{
如果(editingStyle==UITableViewCellEditingStyleDelete){
//从数据源中删除该行。
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]和RowAnimation:UITableViewRowAnimationFade];
}   
else if(editingStyle==UITableViewCellEditingStyleInsert){
//创建相应类的新实例,将其插入数组,并向表视图添加新行。
}   
}
*/
/*
//替代以支持重新排列表视图。
-(void)tableView:(UITableView*)tableView移动rowatinexpath:(nsindepath*)从indepath到indepath:(nsindepath*)到indepath{
}
*/
/*
//重写以支持表视图的条件重新排列。
-(BOOL)tableView:(UITableView*)tableView可以移动rowatinexpath:(nsindepath*)indepath{
//如果不希望该项目可重新订购,则返回“否”。
返回YES;
}
*/
#布拉格标记-
#pragma标记表视图委托
-(void)tableView:(UITableView*)tableView未选择RowatineXpath:(NSIndexPath*)indexPath{
//导航逻辑可能位于此处。创建并推送另一个视图控制器。
/*
*detailViewController=[[alloc]initWithNibName:@“bundle:nil];
// ...
//将选定对象传递给新的视图控制器。
[self.navigationController pushViewController:detailViewController动画:是];
[详细视图控制器发布];
*/
}
#布拉格标记-
#布拉格马