проблема передачи идентификатора - PullRequest
0 голосов
/ 13 октября 2011

Это кажется очень простой вещью, но я не знаю, как это сделать.

На данный момент у меня есть rootView с заполненными континентами:

enter image description here

Код:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}

// Configure the cell.

    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    //Continent is the class. continents is an array to store data
    Continent *cont=[self.continents objectAtIndex:[indexPath row]]; 
    cell.textLabel.text=cont.continentName;
    return cell;
    }

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
Continent *cont=[self.continents objectAtIndex:[indexPath row]];
SelectedContinent* selectedContinent=[[SelectedContinent alloc] initWithNibName: @"SelectedContinent" bundle: nil];

//NSLog(@"%@",cont.continentName);
[self.navigationController pushViewController: selectedContinent animated: YES];
[selectedContinent setTitle:cont.continentName];
[selectedContinent setContinentID:cont.continentID];
[selectedContinent release];
}

Я создал новый viewcontroller с nib-файлом.Дал ему tableView.И теперь мне нужно заполнить страны из файла SQLite.Я создал класс DBAccess, который должен был выполнять все манипуляции с БД, и для каждого континента был написан специальный метод.Затем мне пришло в голову, что написание многих методов - глупая идея, и универсальный метод появился в мире:

-(NSMutableArray*)getTheCountriesEurope:(int)continentID
{
NSMutableArray* euCountriesArray=[[[NSMutableArray alloc]init]autorelease];
NSString* sqlContinents = [NSString stringWithFormat:
                   @"SELECT countries.countryID,countries.countryName\
                   FROM countries\
                   WHERE countries.relativeToContinentID=%i"
                   ,continentID];
/*const char* sqlContinents="SELECT countries.countryID,countries.countryName\
FROM countries\
WHERE countries.relativeToContinentID=?";*/
sqlite3_stmt *statement;
int sqlResult = sqlite3_prepare_v2(database, sqlContinents, -1, &statement, NULL);
if ( sqlResult== SQLITE_OK)
{
    while (sqlite3_step(statement) == SQLITE_ROW)
    {
        Country *countryObj = [[Country alloc] init];
        char *countryName = (char *)sqlite3_column_text(statement, 1);
        countryObj.countryID = sqlite3_column_int(statement, 0);
        countryObj.countryName = (countryName) ? [NSString stringWithUTF8String:countryName] : @"";
        [euCountriesArray addObject:countryObj];
        NSLog(@"%@",countryObj.countryName);
        [countryObj release];
    }
    sqlite3_finalize(statement);
}
else
{
    NSLog(@"Problem with the database:"); 
    NSLog(@"%d",sqlResult);
}
return euCountriesArray;

 }

в любом случае, у этого метода также есть проблемы, и мне сказали реализовать int sqlite3_bind_int (sqlite3_stmt *,int, int);а также метод.

Ну, на данный момент моя проблема в том, что Я не могу поймать значение continentID из класса RootViewController Мне нужно, чтобы оно передавалось методу thisзначение в качестве параметра.

Правильно ли я поступил, когда назначил таким образом countryID?

 [selectedContinent setTitle:cont.continentName];
 [selectedContinent setContinentID:cont.continentID];

в RootViewController. Если да, то как получить значение этой переменной?

В тот момент, когда я нажимаю на другое представление, я вижу только название (по крайней мере, оно показывает право)

SOS

enter image description here

1 Ответ

0 голосов
/ 13 октября 2011

Вам необходимо присвоить значения перед тем, как нажать представление.

[selectedContinent setTitle: cont.continentName];[selectedContinent setContinentID: cont.continentID];[self.navigationController pushViewController: selectedContinent animated: YES];

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...