How to show UIActivityIndicationView when loading data - iphone

I am trying to show an indicator view when loading data in viewDidLoad but the loading starts before i display the indicator, i guess that is because the view is not loaded until after. I have been reading a bit about this but just cannot get it to work.
What i would want is to display the activity indicator during the loading of the files into the database.
I have been doing testing so the code structure may look a bit weird.
Could someone nice please give me a hint, or a link, how to fix this so the activity indicator is shown when/if data is loaded from the .txt files into the DB?
- (void)viewDidLoad {
[super viewDidLoad];
self.title = #" ";
loadActivityIndicator.hidden = TRUE; // Hide UIActivityIndicationView at start
[self loadDataIfNeeded];
}
-(void)loadDataIfNeeded {
NSFileManager *fileManager = [NSFileManager defaultManager];
myFileArray = [[NSMutableArray alloc]init];
//======SET THE FILE INPUT NAME======//
qFileTxtName = #"110615";
[myFileArray addObject:qFileTxtName];
//===================================//
// CHECK IF THE FILE EXISTS
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:#"checkQuestionFile.plist"];
if([fileManager fileExistsAtPath:path]) {
NSArray *readKeyFileName = [[NSArray alloc] initWithContentsOfFile:path];
if ([[readKeyFileName objectAtIndex:0] isEqualToString:qFileTxtName]) {
//==== THERE IS NO UPDATED QUESTION .txt FILE ====//
}
else {
//==== THERE IS AN UPDATED QUESTION .txt FILE ====//
// SET UP UIActivityIndicator view to show that work is ongoing
loadActivityIndicator.hidden = FALSE;
[loadActivityIndicator startAnimating];
//==== SET UP PATH FOR ALL FILES====//
NSString *aString = [[NSString alloc]init];
aString = [#"questions_famquiz_hard_" stringByAppendingString:qFileTxtName];
NSString *path1 = [[NSBundle mainBundle] pathForResource:aString ofType:#"txt"];
aString = [#"questions_famquiz_medium_" stringByAppendingString:qFileTxtName];
NSString *path2 = [[NSBundle mainBundle] pathForResource:aString ofType:#"txt"];
aString = [#"questions_famquiz_easy_" stringByAppendingString:qFileTxtName];
NSString *path3 = [[NSBundle mainBundle] pathForResource:aString ofType:#"txt"];
AccessQuestionsDB *accessQuestionDataFunction = [AccessQuestionsDB new];
idCounter = [accessQuestionDataFunction populateTheDatabase: path1 theID:0 firstTime: YES];
idCounter = [accessQuestionDataFunction populateTheDatabase: path2 theID:idCounter firstTime: NO];
idCounter = [accessQuestionDataFunction populateTheDatabase: path3 theID:idCounter firstTime: NO];
//==UPDATE THE PLIST==//
[myFileArray writeToFile:path atomically: TRUE];
// Stop UIActivityIndicator as activity is over
loadActivityIndicator.hidden = TRUE;
[loadActivityIndicator stopAnimating];
}
} else {
//== If file not found write a new file ==//
[myFileArray addObject:qFileTxtName];
[myFileArray writeToFile:path atomically: TRUE];
}
}
PROBLEM SOLVED
I replaced the call
[self loadDataIfNeeded];
with;
[NSThread detachNewThreadSelector:#selector(loadDataIfNeeded) toTarget:self withObject:nil];
to achieve multi threading according to the recommendation from Jonah :-)

You are loading your data synchronously in the main thread. That means that the main thread, the one responsible for drawing the UI, is busy loading your data and will not have a chance to update your view until after your loadDataIfNeeded method finishes (at which point you don't want to show your activity indicator to be visible anymore anyway).
Display your activity indicator on the main thread but then allow the main thread's run loop to continue and instead perform expensive operations (like loading data or performing network requests) asynchronously on a secondary thread.
Look at NSThread, NSObject's -performSelectorInBackground:withObject:, and NSOperationQueue for different options for performing tasks off of the main thread.

The book "IOS Recipes" by Matt Drance has a recipe that talks about how to do this best. You can get this recipe as a free excerpt from the book at http://media.pragprog.com/titles/cdirec/activity.pdf
You can find the source code for the recipe on the book page at http://pragprog.com/titles/cdirec/ios-recipes

In your viewDidLoad add
UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
activityView.frame = CGRectMake(0, 0, 44, 44);
activityView.center = self.view.center;
activityView.tag = 99;
[activityView startAnimating];
[self.view addSubview: activityView];
[activityView release];
Then in your load method after you finish loading just remove your activity indicator from super view.
So in your loadDataIfNeeded after loading add
[[self.view viewWithTag:99] removeFromSuperview];

Related

Storing and retrieving images on iPhone efficiently

I have an application which donwloads several images and stores them on the phone. In total it will probably required around 20 images tops. I need to be able to retrieve any of these images at will depending on what screen the user is on. These images will be stored indefinitely, so I don't want to use temp directory.
At present I have a class named Images with these methods
- (void) cacheImage: (NSString *) ImageURLString : (NSString *)imageName
{
NSURL *ImageURL = [NSURL URLWithString: ImageURLString];
// Generate a unique path to a resource representing the image you want
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docDir = [paths objectAtIndex: 0];
NSString *docFile = [docDir stringByAppendingPathComponent: imageName];
// Check for file existence
if(![[NSFileManager defaultManager] fileExistsAtPath: docFile])
{
// The file doesn't exist, we should get a copy of it
// Fetch image
NSData *data = [[NSData alloc] initWithContentsOfURL: ImageURL];
UIImage *image = [[UIImage alloc] initWithData: data];
// Is it PNG or JPG/JPEG?
// Running the image representation function writes the data from the image to a file
if([ImageURLString rangeOfString: #".png" options: NSCaseInsensitiveSearch].location != NSNotFound)
{
[UIImagePNGRepresentation(image) writeToFile: docFile atomically: YES];
}
else if([ImageURLString rangeOfString: #".jpg" options: NSCaseInsensitiveSearch].location != NSNotFound ||
[ImageURLString rangeOfString: #".jpeg" options: NSCaseInsensitiveSearch].location != NSNotFound)
{
[UIImageJPEGRepresentation(image, 100) writeToFile: docFile atomically: YES];
}
}
}
- (UIImage *) getCachedImage : (NSString *)imageName
{
NSArray *paths = NSSearchPathForDirectoriesInDomains
(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString* cachedPath = [documentsDirectory stringByAppendingPathComponent:imageName];
UIImage *image;
// Check for a cached version
if([[NSFileManager defaultManager] fileExistsAtPath: cachedPath])
{
image = [UIImage imageWithContentsOfFile: cachedPath]; // this is the cached image
}
else
{
NSLog(#"Error getting image %#", imageName);
}
return image;
}
-(void)getImages
{
//example
NSString *image1URL = #"http://test/image1.png";
NSString *image2URL = #"http://test/image2.png";
NSString *image3URL = #"http://test/image3.png";
[self cacheImage:sLogo: #"Image1"];
[self cacheImage:sBlankNav: #"Image2"];
[self cacheImage:buttonLarge :#"Image3"];
}
-(void) storeImages
{
image1 = [self getCachedImage:#"Image1"];
image2 = [self getCachedImage:#"Image2"];
image3 = [self getCachedImage:#"Image3"];
}
So I use the code like this
Images *cache = [[Images alloc]init];
[cache storeImages];
The get images method is called once when the app first starts to get the images, it isn't called again after that, unless the images on the server are updated and I need to retrieve the updated ones.
The code works, but the problem is when I navigate to a screen that uses it, there is a very slight delay before the screen loads as it is loading the images.
My application is a tabbed application, so it begins on tab 1, I click tab 2 which implements the code, there will be a slight pause the first time it loads. It doesn't last very long, but it is noticeable and is very annoying. After that it is fine, as it is already loaded. However with navigation controller, every time you move from the first VC to the second VC, the method will be called again, so each time you navigate the delay will be there.
The images are not very big, biggest one is 68kb, others are much smaller than that. At present I am just testing with 5 images. Is there a more efficient way of storing and retrieving images, or am I doing something wrong with my code? I need to be able to retrieve these images without any noticeable delay in order for my application to remain fluid and not jerky or clunky.
Thanks in advance!!
You have two options to do the image loading work on a background thread - use Grand Central Dispatch or NSInvocationOperation. GCD might be considered the cleaner of the two:
dispatch_queue_t q = dispatch_get_global_queue(0, 0);
dispatch_queue_t main = dispatch_get_main_queue();
dispatch_async(q, ^{
//load images here
dispatch_async(main, ^{
// show on main thread here
});
});
you have delay because you're downloading data synchronously
// NSData *data = [[NSData alloc] initWithContentsOfURL: ImageURL];
Try some smart library like SDWebImage:
it lets you download image asynchronously while you still can display a local image (a proxy image). By the way, you still get cache image for free. So even if u are on local, you can still catch previously downloaded images
https://github.com/rs/SDWebImage
A must have

Image storage as byte code locally from XML parsing & display if it is stored Otherwise go for parsing.

I am having an app in which at the time of launcing the app XML parsing is giving Main category from URL like hp, dell, etc...I am displaying it in the Tableview.
Then on click of particular cell i can get the detail of main category means its subcategory like http://www.dealsbell.com/findcoupon.php?store=hp
Here also i am getting data properly after parsing.
But my concern over here is, in ( http://www.dealsbell.com/findcoupon.php?store=hp ) this link i am getting images.
Each particular subcategory will have a same image. So i want to do something like that the image if first time loaded from the URL then it will display image from parsing otherwise i would like to store that image as its byte code in folder / file / in any way in my device on first parsing.
If once the image is stored to the particular way in my device next time when i will go to see the subcategory it will first check this image is stored locally to my device or not.
If yes then it should go to the particular location to fetch this local image & display it to each cell otherwise will parse & display image.
I hope you are getting, what i want to ask.
Please guide me, how can this be possible & what is the way to get result.
If any example or link you can suggest, then it will be more efficient to me.
Thanks in advance.
There are probably two ways to achive this.
Get NSData out of Image and hold that in UserDefaults or database.
Dump image in application folder and pick image from that place.
So whenever you try to load image for subcatogory check at one of place and if present use that. IF in case you have stored image and if any updated image comes,then remove previous copy and store new one.
-(void) SaveImageinDocumentWithName:(UIImage*) aUIImage Name:(NSString*) aName
{
if(aUIImage)
{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSMutableString* str = [[NSMutableString alloc] initWithCapacity:300];
[str appendString:documentsDirectory];
[str appendString:#"/"];
[str appendString:aName];
NSFileManager *fileManager = [NSFileManager defaultManager];
[UIImagePNGRepresentation(aUIImage) writeToFile:str atomically:YES];
if(str)
{
[str release];
str = nil;
}
if(fileManager)
{
[fileManager release];
fileManager = nil;
}
[pool release];
}
}
-- Getting saved image
-(UIImage*)GetSavedImageWithName:(NSString*) aFileName
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSMutableString* str = [[NSMutableString alloc] initWithCapacity:300];
[str appendString:documentsDirectory];
[str appendString:#"/"];
[str appendString:aFileName];
NSFileManager *fileManager = [NSFileManager defaultManager];
BOOL success = [fileManager fileExistsAtPath:str];
NSData *dataToWrite = nil;
UIImage* image = nil;
if(!success)
{
}
else
{
image = [[UIImage alloc] initWithContentsOfFile:str];
}
if(dataToWrite)
{
[dataToWrite release];
dataToWrite = nil;
}
if(str)
{
[str release];
str = nil;
}
if(fileManager)
{
[fileManager release];
fileManager = nil;
}
return image;
}
Parse dealsbell.com/wp-content/uploads/mobile/hp.gif and take only hp.gif
NSString *strImage = [NSString stringWithFormat:#"%#",aBook.image];
UIImage* image = [self GetSavedImageWithName:strImage];
if(image) // This means Image exists
{
// Do what you want
}
else
{
NSURL *url4Image = [NSURL URLWithString:strImage];
NSData *data = [NSData dataWithContentsOfURL:url4Image];
if(data != NULL)
{
image =[[UIImage alloc] initWithData:data];
[self SaveImageinDocumentWithName:image Name:strImage]; // save for future ref.
}
else
{
image =[UIImage imageNamed:#"icon.png"];
}
}

saving changed text in textview loaded from NSMutableDictionary

I have a UITextView in a DetailViewController with some text which is loaded from a NSMutableDictionary in the MainViewController. Here is the code for that;
- (void) coverflowView:(TKCoverflowView*)coverflowView coverAtIndexWasDoubleTapped:(int)index{
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:#"DetailViewController" bundle:nil];
if ((int)index == 0) {
NSMutableDictionary *myDictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"This is some text", #"textkey", nil];
detailViewController.myDictionary = myDictionary;
}
I have loaded the string from this into my DetailViewController with this code;
self.myText.text = [(NSMutableDictionary *)myDictionary objectForKey:#"textkey"];
Also in my viewDidLoad I have created a RightBarButton named 'Save' which I use to hide the keyboard when the viewer is done editing. I would like this button to also save the changes the viewer enters into the UITextView (as well as the original text).
This is the code for the rightBarButton;
UIBarButtonItem *saveButton =[[UIBarButtonItem alloc]
initWithTitle:#"Save"
style:UIBarButtonItemStyleBordered
target:self
action:#selector(textViewDidChange:)];
self.navigationItem.rightBarButtonItem = saveButton;
Lastly I have code which envokes the textVidewDidChange and hides the keyboard. I am trying to also have it save the changes to the textView but it doesn't.
-(void)textViewDidChange:(UITextView *)textView;
{
if( textView == myText )
[myDictionary setValue:myText.text forKey:#"textkey"];
[myText resignFirstResponder];
}
Can anyone help me accomplish this. I simply want to save the changes to the UITextView back to the NSMutableDictionary. (or maybe not so simply)
I have changed the button to
`UIBarButtonItem *saveButton =[[UIBarButtonItem alloc]
initWithTitle:#"Save"
style:UIBarButtonItemStyleBordered
target:self
action:#selector(didChangeValueForKey:)];
self.navigationItem.rightBarButtonItem = saveButton;`
and other code to ;
`-(void)didChangeValueForKey:(NSString *)key{
NSError *error;
[myDictionary setValue:[self myText].text forKey:#"textkey"];
[myText resignFirstResponder];
NSLog(#"%#", [myDictionary valueForKey:#"textkey"]);
}
My NSLog shows the changes but when I reopen the app they are gone, not saved. Can one save directly to the NSMutableDictionary?
I read a lot on persistent data. Thought NSData or Plist but try as I may not doing well.
Can someone suggest a good tutorial on this?
I looked at suggested link and added this (bold part) to my code.
`-(void)didChangeValueForKey:(NSString *)key{
/* NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:[(NSMutableDictionary *)myDictionary objectForKey:#"textkey"]];*/
NSError *error;
[myDictionary setValue:[self myText].text forKey:#"textkey"];
**[myDictionary writeToFile:#"textkey" atomically:YES];**
[myText resignFirstResponder];
NSLog(#"%#", [myDictionary valueForKey:#"textkey"]);
}`
As you can see I also tried getting the path using [NSHomeDirector] above and then replaced
#"textkey" with path. I can still see the changes in NSLog (either way) but there is no change when I reload the view or relaunch the app.
I have change things so that I am saving a text file of the text in the textview with the name gotten from the dictionary so that each time a different detailView is loaded depending on the image selected in the mainViewController.
This is my dictionary entry in the mainViewController;
`if ((int)index == 0) {
NSMutableDictionary *myDictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys:
//here is where I want to access the text file name to load in the UITextView in my DetailView
#"first View Text", #"textkey2",
//This is where I give the text file of the changed text its name for each different view of the DetailView
#"first View Text", #"textkey3",nil];
detailViewController.myDictionary = myDictionary;
}`
Next is the code I use to save the changes to the textView using the UIbarbuttonright
`- (void)saveAction:(id)sender {
[self.myText2 resignFirstResponder];
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [documentPaths objectAtIndex:0];
NSString *documentTXTPath = [documentsDirectory stringByAppendingPathComponent:[(NSMutableDictionary *)myDictionary objectForKey:#"textkey3"]];
NSString *savedString = myText2.text;
NSLog(#"The Save file is:%#", savedString);
[savedString writeToFile:documentTXTPath atomically:YES
encoding:NSUTF8StringEncoding error:NULL];
}`
I have checked this and the file is saved in the documents folder under the name of First View Text and it does contain the changed text.
I am having problems loading the text file contents into the UITextView.
Using the code I have I get the path to the textkey2 object (First Text View) not the contents of the file.
`NSString *textName = [myDictionary objectForKey:#"textkey2"];
NSArray *paths2 = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsDirectory2 = [paths2 objectAtIndex:0];
NSString *fullPath2 = [documentsDirectory2 stringByAppendingPathComponent:textName];
/* self.myText2.text = fullPath2;*/
self.myText2.text = [NSString stringWithContentsOfFile:fullPath2 encoding:NSUTF8StringEncoding error:NULL];`
I replaced this last line with the one that isn't commented out and it works fine. For anyone who want to know.
You need to implement data persistence, e.g. saving the text into permanent storage that you can retrieve again when you reload the view later on.

How to refresh images using HJCache?

I'm trying to display an image from a webcam in my app using HJCache.
The webcam refreshes its image every 5 minutes.
I'd like to have a refresh button, so that users could click it to see a new image (if available).
My code so far:
-(void)viewDidLoad {
// init HJObjManager
objMan = [[HJObjManager alloc] initWithLoadingBufferSize:6 memCacheSize:20];
// refresh button
UIBarButtonItem *buttonRefresh = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
target:self
action:#selector(refreshPhoto:)];
self.navigationItem.rightBarButtonItem = buttonRefresh;
[buttonRefresh release];
NSURL *url = [NSURL URLWithString: #"http://webcamurl"];
img1.url = url;
[self.objMan manage:img1];
}
-(IBAction) refreshPhoto: (id) sender {
// ?
}
Could you give me an hint on how to implement refreshPhoto?
Edit: ender pointed me to emptyCache. If I understand it ok, it should be used by HJMOFileCache, so my code now is:
-(void)viewDidLoad {
NSString *documentsDirectory;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
documentsDirectory = [paths objectAtIndex:0];
documentsDirectory = [documentsDirectory stringByAppendingPathComponent:#"imageCache/"];
objMan = [[HJObjManager alloc] initWithLoadingBufferSize:6 memCacheSize:20];
HJMOFileCache* fileCache = [[[HJMOFileCache alloc] initWithRootPath:documentsDirectory] autorelease];
fileCache.fileCountLimit = 100;
fileCache.fileAgeLimit = 300; // 5 min
objMan.fileCache = fileCache;
// refresh button
UIBarButtonItem *buttonRefresh = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
target:self
action:#selector(refreshPhoto:)];
self.navigationItem.rightBarButtonItem = buttonRefresh;
[buttonRefresh release];
NSURL *url = [NSURL URLWithString: #"http://webcamurl"];
img1.url = url;
[self.objMan manage:img1];
[super viewDidLoad];
}
-(IBAction) refreshPhoto: (id) sender {
[self.objMan.fileCache emptyCache];
[self.objMan manage:img1];
}
It doesn't work though, when I click the refresh button nothing happens, the image does not refresh.
Any idea?
Edit: ender suggested that maybe the cache files do not get deleted by emptyCache (if I understand it right), but it looks like they actually do.
From NSLog before and after the emptyCache:
2011-09-09 16:57:33.842 Ready dir before emptyCache: (
"http:__www.meteogallipoli.it_cam_cam1.jpg"
)
2011-09-09 16:57:33.845 Loading dir before emptyCache: (
)
2011-09-09 16:57:33.856 Ready dir after emptyCache: (
)
2011-09-09 16:57:33.859 Loading dir after emptyCache: (
)
"Ready" and "Loading" are the directories where objMan stores files already downloaded and being downloaded, respectively.
Maybe the problem is in making objMan manage the image again?
I think its because you configured the object manager with both a file cache and a memory cache. When you empty the file cache, there are still images in the memory cache? Try instanciating the object manager with
if you only have an image, you can use [objMan emptyCache];
If you want to refresh only an image, you can save it in a different dir and use this method instead:
[objMan deleteAllFilesInDir:path];
Of course, you will have to make the query again:
[self.objMan manage:img1];

iPhone - track back button event

I have a tableView which lists the contents of my document directory. I have some zip files in that. If I touch a file in the tableView, the corresponding zip file is unzipped and extracted in a temporary directory(newFilePath in my case). The contents unzipped is listed in the next tableView. When I touch the back button, the contents in the directory is listed again.
For example, consider that I have four zip files in my document directory.
songs.zip, videos.zip, files.zip, calculation.zip
When I run the application, all the four files are listed in the tableView. When I touch songs.zip, this file is extracted in the newFilePath and its contents are pushed to the next tableView. When I touch back, the previous tableView, i.e, the four files in the document directory are listed again. Everything works perfect.
The problem is, the extracted files in the newFilePath remains there itself. They occupy the memory unnecessarily. I want them to be removed from that path when I touch the back button, i.e, I want to make newFilePath empty when the back button is touched.
I tried for it. But, no use. I tried removeItemAtPath: method in viewWillAppear: and also in viewWillDisappear:. But it didnt work in both the cases.
Is there any other method to track the action of the back button? I want an event to take place when the back button is touched. So please help me by sharing your ideas. Here is my code for your verification.
This is my didSelectRowAtIndexPath:
NSString *filePath = //filePath
if([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
NSLog(#"File exists at path: %#", filePath);
} else {
NSLog(#"File does not exists at path: %#", filePath);
}
ZipArchive *zip = [[ZipArchive alloc] init];
NSString *newFilePath = //newFilePath
[[NSFileManager defaultManager] createDirectoryAtPath:newFilePath withIntermediateDirectories:NO attributes:nil error:nil];
BOOL result = NO;
if([zip UnzipOpenFile:filePath]) {
//zip file is there
if ([zip UnzipFileTo:newFilePath overWrite:YES]) {
//unzipped successfully
NSLog(#"Archive unzip Success");
result= YES;
} else {
NSLog(#"Failure To Extract Archive, maybe password?");
}
} else {
NSLog(#"Failure To Open Archive");
}
iDataTravellerAppDelegate *AppDelegate = (iDataTravellerAppDelegate *)[[UIApplication sharedApplication] delegate];
//Prepare to tableview.
MyFilesList *myFilesList = [[MyFilesList alloc] initWithNibName:#"MyFilesList" bundle:[NSBundle mainBundle]];
//Increment the Current View
myFilesList.CurrentLevel += 1;
viewPushed = YES;
//Push the new table view on the stack
myFilesList.directoryContent = [AppDelegate getTemporaryDirectoryItemList:newFilePath];
[myFilesList setTitle:detailedViewController.strName];
[self.navigationController pushViewController:myFilesList animated:YES];
[myFilesList release];
Thank you for your answers.
for creating your own action you need custom back button.But i think viewWillDisAppear also can do solve your problem.
use this code for solving your problem
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectoryPath = [paths objectAtIndex:0];
NSString *databaseFile = [documentsDirectoryPath stringByAppendingPathComponent:#"newFilePath"];
NSFileManager *fileManager = [NSFileManager defaultManager];
[fileManager removeItemAtPath:databaseFile error:NULL];
This may help you.
Edit:
NSString *documentsDirectoryPath = [paths objectAtIndex:0];
NSString *secondaryDirectoryPath = [secondaryDirectoryPath stringByAppendingPathComponent:#"secondary"];
NSString *databaseFile = [documentsDirectoryPath stringByAppendingPathComponent:#"newFilePath"];
use these lines in your code if you have directory inside the document directory.
you can add the custom back button on Navigation Bar. Create the method, which will fire on click event of Back button.