I’m checking if file already exists and if it is, I’m alerting the user if he wants o replace the file. I’m using alert view and a delegate.
However when i run it using the simulator by the time the user selects YES or NO the program already run pass it and the blnVal has NO value regardless
I’m not sure what i’m missing here.?
(I searched the database here but couldn’t find any related specific question)
-(void) chkFile2Save
{
short tst;
NSString* documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString* foofile = [documentsPath stringByAppendingPathComponent:pln2Save.text];
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:foofile];
if(fileExists)
{
blnVal=NO;
[self AskFileSave];
}
//blnVal always NO for whatever reason ... ?
if(blnVal==NO)
tst=5;
//...
else {
tst=10;
//..
}
}
- (void) AskFileSave
{
UIAlertView *alertFileSave = [[UIAlertView alloc] initWithTitle:@"" message:@"File already exists. Override the file with current data?" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
[alertFileSave setTag:10];
[alertFileSave show];
[alertFileSave release];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
//override file exists
if([alertView tag]==10)
{
if(buttonIndex == 1)
{
blnVal=YES;
}
else
{
blnVal=NO;
}
}
}
you are calling
that will execute
than the execution will go back to :
You should move that part of the code to delegate method, There you have the option what the user selected, because the UIAlerView will not stop the code execution.
I hope it helps!