データは全てsqliteで引っ張ってきており、litaを使っております。
概要を簡単に示させて頂きます。
Firstviewcontrollerには店舗のリストが書かれており、
店舗を押すと、店舗情報が記載されているdetailviewcontrollerに飛びます。
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:[NSBundle mainBundle]];
detailViewController.mission = [mMissions objectAtIndex:indexPath.row];
[self.navigationController pushViewController:detailViewController animated:YES];
}
ここで、渋谷を押した場合は、Firstviewcontrollerに載っている渋谷だけの店舗を表示したいのですが、ここでの画面の遷移のさせ方がわかりません。
secondviewcontrollerのコードは下記です。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"Mission.db"];
FMDatabase* db = [FMDatabase databaseWithPath:writableDBPath];
[db setShouldCacheStatements:YES];
pArray = [[NSMutableArray alloc] init];
[db open];
for (int i=0; i<[aMission count]; i++){
if(section == i){
FMResultSet *prs = [db executeQuery:@"select distinct Place from Mission where area = ?", [aMissions objectAtIndex:i]];
while ([prs next]) {
Mission *mission = [[Mission alloc] init];
mission.place = [prs stringForColumn:@"Place"];
[pArray addObject:mission.place];
}
return [pArray count];
}
}
[db close];
return 0;
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
for (int i = 0; i < [aMissions count]; i++){
if(section == i){
NSString *str = [[NSString alloc] initWithFormat:@"%@",[aMissions objectAtIndex:i]];
return str;
}
}
return 0;
}
//tableのセルに表示するデータの指定
- (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];
}
pArray = [[NSMutableArray alloc] init];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"Mission.db"];
FMDatabase* db = [FMDatabase databaseWithPath:writableDBPath];
[db setShouldCacheStatements:YES];
[db open];
for (int i=0; i<[aMissions count]; i++){
if(indexPath.section == i){
FMResultSet *prs = [db executeQuery:@"select distinct Place from Mission where area = ?", [aMissions objectAtIndex:i]];
while ([prs next]) {
Mission *mission = [[Mission alloc] init];
mission.place = [prs stringForColumn:@"Place"];
[pArray addObject:mission.place];
}
cell.textLabel.text = [pArray objectAtIndex:indexPath.row];
}
}
[db close];
return cell;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
{
ここにて、Firstviewcontrollerに記載されいるリストの中からエリアの一致するものだけを表示するという処理を書けばいいのですが、どのようにかけばいいのかが理解できません。
}
どうか御教授頂けると幸いです。