tags:

views:

89

answers:

0

Hi I have a little problem, I write some methods for pass a variable to appdelegate, the code for pass the var is correct, if I put 1,2 or 3 the variable on appdelegate is 1,2 or 3, the problem is when I use another dynamic varbiable, this var depending on what button was clicked. I put an NSLog on the variable in appdelegate and I see that it was define at the start of my application and it is not update, then I think that need to refresh. Here is my code:

class.h
 int TAG;
 int PassTag;

class.m

...code for create a loop button

- (void) listener:(id) sender
{
  int index = [sender tag] - TAG_INDEX;
 iIngAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
 ContenutoObject *co = [delegate.array_contenuti objectAtIndex:index];

 TAG = [[co id] intValue];  THIS IS THE VAR
 [self varID];

 // Push view controller as appropriate
 detail = [[ListaArgomentoController alloc] initWithNibName:@"ListaArgomento" bundle:[NSBundle mainBundle]];
 [self.navigationController pushViewController:detail animated:YES];

 // Set the title of the view to the argoment
 self.detail.title = [co id];
 [detail release];
}

- (int) varID
{

 PassTag = TAG;
 NSLog(@"PassTag = %d",PassTag); 
 return PassTag;
}

and

delegate.h
int variabileID;
@property int variabileID;


delegate.m

...code for charge database

-(void) readArgFromDatabaseArgomento {

 ListView *my_ID = [[ListView alloc] init];
 variabileID = [my_ID varID];
 NSLog(@"variabileID = %d",variabileID);


 // Setup the database object
 sqlite3 *databaseArg;
 // Init the argoments Array
 arrayContenutiArgomento = [[NSMutableArray alloc] init];
 // Open the database from the users filessytem
 if(sqlite3_open([databasePath UTF8String], &databaseArg) == SQLITE_OK) {
  // Setup the SQL Statement and compile it for faster access

  // HERE I want to use variabileID on the database query for select the correct typo of a city

  const char *sqlStatement = [[NSString stringWithFormat:@"select * from TIPOLOGIA WHERE id_materia='%d'",variabileID] UTF8String];

  // const char *sqlStatement = "select * from TIPOLOGIA ";
  sqlite3_stmt *compiledStatement;
  if(sqlite3_prepare_v2(databaseArg, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
   // Loop through the results and add them to the feeds array
   while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
    // Read the data from the result row
    NSString *aID = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 0)];
    NSString *aidCitta = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];
    NSString *aTipologia = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)];

    // Create a new argoments object with the data from the database
    ContenutoObjectArgomento *contenutoArgomento = [[ContenutoObjectArgomento alloc] initWithName:aID idCitta:aidCitta Tipologia:aTipologia];
    [arrayContenutiArgomento addObject:contenutoArgomento];

    [contenutoArgomento release];
   }
  }


  // Release the compiled statement from memory
  sqlite3_finalize(compiledStatement);

 }
 sqlite3_close(databaseArg);
}

I want to refresh tha variable "variablieID", can you help me?