开发者

my filemanager not connecting to my directory

I want to simply display array data of my directory for which i tried this code..directory is in resources folder..code is below..may i know what is going wrong..data is not displaying after i press a button

@implementation filemanagerV开发者_运维百科iewController

- (void)viewDidLoad {
    [super viewDidLoad];

    filemag =[NSFileManager defaultManager];
}


-(IBAction)buttonpress:(id)sender
{
    filelist=[filemag directoryContentsAtPath:@"directory.plist"];
    count=[filelist count];

  //i used a 'for loop here' for i<count

   NSLog(@"%@",[filelist objectAtIndex:i]);
}


"directory.plist" is not a path


NSFileManager takes absolute path, you are passing directory.plist then that directory must exist in root directory otherwise it will return null.

To get the resource folder path use NSBundle class, you can use may be following api to get path:
+ (NSBundle *)mainBundle
+ (NSArray *)pathsForResourcesOfType:(NSString *)extension inDirectory:(NSString *)bundlePath

PS:Documentaion says the API you are using is deprecated

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜