这似乎是一件非常简单的事情,但我不知道该怎么做。
目前我已经填充了各大洲的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];
}
我用nib文件创建了一个新的viewcontroller。给他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
答案 0 :(得分:0)
您需要在推送视图之前指定值。
[selectedContinent setTitle:cont.continentName]; [selectedContinent setContinentID:cont.continentID]; [self.navigationController pushViewController:selectedContinent animated:YES];