2

in my program i create a list of Item in a view. When I click on a particular item, i open another view for see the information relative to the item.

But when I come back to the previous view, the navigation controller don't delete the view from the stack, in fact, after I'm returned to the previous view controller, if I click on another or the same Item for show info, the navigation controller views are the same number plus 1, and when i try to come back he load first the same view of item info and then load the lists of the item.

EXAMPLE:

view lists of items: view A

view information: view B

step 1: load items in view A

step 2: click on item 1 in view A and push view B on the stack

step 3: pop B from A

step 4: click on item 2 in view A and push view B on the stack

on step 4 my stack is: A - B - B.... why?

EDIT:

Here is STEP 2:

-(void) clickOnSpesa:(NSNotification*)notification
{
    NSDictionary *userInfo = notification.userInfo;
    Spesa *spesa = [userInfo objectForKey:@"notaSpesa"];

    //Cambio View
    NuovaSpesa *viewSpesa = [[NuovaSpesa alloc] initWithNibName:nil bundle:nil];
    NSLog(@"creo la view per visualizzare la spesa");
    [viewSpesa initWithSpesa:spesa];
    [self.navigationController pushViewController:viewSpesa animated:YES];
}

STEP 3:

-(void) previousView:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

InitWithSpesa:

-(void)initWithSpesa:(Spesa *)spesa
{   
    //Info
    [GeneralManager showInvioTable];

    self.spesaFromGestione = spesa;

    //Setto il resto come non modificabile se la spesa non lo è
    bool isModificable = true;

    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"dd/MM/yyyy"];
    NSString *stringDate = [formatter stringFromDate:spesa.creationDate];

    //Get delle NoteSpesa in tutte le date
    SDLDatabase *db = [[SDLDatabase alloc] initWithFile:dbPath];
    NSString *sql = [NSString stringWithFormat:@"SELECT * FROM invio WHERE data='%@'", stringDate];
    NSMutableArray *resultSpese = [db selectAllFrom:sql];
    [db close];

    if ([resultSpese count] > 0) {
        isModificable = false;   //Data già inviata e non può essere modificata
    }

    //Inserisco i valori nei relativi campi
    [btnCalendario setTitle:stringDate forState:UIControlStateNormal];
    [btnSpese setTitle:spesa.type.nome forState:UIControlStateNormal];
    [txtQuantita setText:[NSString stringWithFormat:@"%d", spesa.quant]];
    [txtCosto setText:[NSString stringWithFormat:@"%.2f", spesa.costo]];
    if (spesa.type.tipoSpesa == TIP_FIXED) {
        [txtCosto setEnabled:false];
        [self.txtCosto setAlpha:0.3];
    }
    [txtNote setText:spesa.note];

    //Foto
    NSArray *photos = [[GeneralManager sharedManager] loadImageForSpesa:spesa];

    //La salvo nel "porta" foto
    for (UIImage *image in photos) {
        [self.scrollerPhoto addPhoto:image];
    }

    if(isModificable){
        //Modificabile
        [btnSalva setTitle:@"Modifica" forState:UIControlStateNormal];
    }else{
        //Non modificabile
        [btnCalendario setEnabled:false];
        [btnSpese setEnabled:false];
        [txtQuantita setEnabled:false];
        [txtCosto setEnabled:false];
        [txtNote setEditable:false];
        [btnScattaFoto setEnabled:false];
        [btnSalva setHidden:true];
        [btnElimina setHidden:true];
    }
}
Allen Walker
  • 866
  • 1
  • 9
  • 17

0 Answers0