2011-10-13 54 views
0

這似乎是一件非常簡單的事情,但我不知道該怎麼做。id傳輸問題

在那一刻我有填充大洲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]; 
} 

我創建了筆尖文件的新視圖控制器。給他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);方法。

好吧,那一刻我的問題是,我無法趕上從RootViewController的的continentID值我需要它這個值饋送到方法的參數。

當我這樣指定countryID時,我做得對嗎?

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

在RootViewController中。 如果是,那麼如何獲取變量的值?

在那一刻,我推另一種觀點我只看到標題(至少它表明右)

SOS

enter image description here

回答

0

你需要你推視圖之前分配值。

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