我似乎无法从逻辑上弄清楚如何为每个分组部分设置一个单独的数组,每个部分在导航控制器的详细视图中显示不同的数据。对于每个组,都有不同的数据,但是第二个视图当前在 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";
}
}