ナビゲーション コントローラーの詳細ビューにそれぞれ異なるデータを表示する、グループ化されたセクションごとに個別の配列を作成する方法を論理的に理解できないようです。グループごとに異なるデータがありますが、現在、2 番目のビューは 1 つの配列から UILabel にデータを表示し、各グループの配列の先頭から開始します。さらに情報が必要な場合はお知らせください。
- (void)viewDidLoad
{
[super viewDidLoad];
//Keeping of Business Names for Detailed View
addressBook=@[@"Clinic 1 Business",@"Clinic 2 Business",@"Clinic 3 Business"];
//holding of clinic names per county
adams=@[@"Clinic 1 Business Listing",@"Clinic 2 Business Listing",@"eeeee"];
allegheny=@[@"Clinic 3 Business Listing",@"Clinic 4 Business Listing"];
armstrong=@[@"Clinic 5 Business Listing",@"Clinic 6 Business Listing",@"Clinic 7 Business Listing"];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
NSLog(@"this is the content of addressBook: \n %@", addressBook);
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
//return addressBook.count;
if(section==0)
{
return [adams count];
}
else if(section==1)
{
return [allegheny count];
}
else if (section==2)
{
return [armstrong count];
}
}
/*
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{
return [NSArray arrayWithObjects:@"Rec", @"A", @"B", nil ];
}
*/
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"abCell";
addressBookCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if(indexPath.section==0)
{
cell.addressBookLbl.text=[adams objectAtIndex:indexPath.row];
}
else if(indexPath.section==1)
{
cell.addressBookLbl.text=[allegheny objectAtIndex:indexPath.row];
}
else if (indexPath.section==2)
{
cell.addressBookLbl.text=[armstrong objectAtIndex:indexPath.row];
}
return cell;
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier]isEqualToString:@"addressBookDetails"]) {
addressBookDetailsViewController *addressDetailsController = [segue destinationViewController];
NSIndexPath *abIndexPath = [self.tableView indexPathForSelectedRow];
int row = [abIndexPath row];
addressDetailsController.addressDetail=@[addressBook[row]];
NSLog(@"this is the content of addressBook: \n %@", addressBook);
}
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
if (section==0) {
return @"Adams County";
}
else if(section==1)
{
return @"Allegheny County";
}
else if(section==2)
{
return @"Armstrong County";
}
}