in my app i have 2 views
view1{
[self.navigationController pushViewController:view2Controoler animated:YES];
}
view2
here when i am pressing back button app is crash without error or warning also in view2 i am using following codepaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSFileManager *manager开发者_如何学Go = [NSFileManager defaultManager];
NSArray *fileList = [manager directoryContentsAtPath:documentsDirectory ];
in xcode last statement shows the warning "directoryContentsAtPath
is depricated" so i try to use
NSArray *fileList = [manager directoryContentsAtPath:documentsDirectory error:NULL];
and this statement shows "NSFileManager
may not respond to directoryContentsAtPath:error
" anyways still I tried to run app and
app crashed with Exception "reason: '-[NSFileManager directoryContentsAtPath:error:]:
unrecognized selector sent to instance 0x6302f50'"
I hope some one know how to solve this issue
Thank you
"
NSFileManager has no class methods other than +defaultManager
. You should be using – contentsOfDirectoryAtPath:error:
with your instance of a file manager.
I think directoryContentsAtPath:
returns an autoreleased object.
If you have directoryContent set up as a @property(nonatomic, retain)
in your header you can set it using
self.directoryContent = [[NSFileManager defaultManager] directoryContentsAtPath: documentsDirectory];
and it will automatically retain the object returned by NSFileManager
, otherwise you could call
directoryContent = [[[NSFileManager defaultManager] directoryContentsAtPath: documentsDirectory] retain];
but be sure to release that object when you no longer need it.
From Apple Documentation
directoryContentsAtPath:
Returns the directories and files (including symbolic links) contained in a given directory. (Deprecated in iOS 2.0. Use contentsOfDirectoryAtPath:error: instead.)
- (NSArray *)directoryContentsAtPath:(NSString *)path
From Apple Documentation Suggest you to use
- (NSArray *)contentsOfDirectoryAtPath:(NSString *)path error:(NSError **)error
精彩评论