这似乎是一件非常简单的事情,但我不知道该怎么做。id传输问题
在那一刻我有填充大洲rootView:
代码:
- (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