iOS 6 アプリに 4 つのセクションに分割されたテーブルがあります。これらのテーブルにはそれぞれ、titleForHeaderInSection で設定したタイトルがあります。didSelectRowAtIndexPath で NSLog を使用してこのタイトルにアクセスする方法を知りたいです。アラートでクリックした行の文字列値が表示されますが、テーブルビュー セクションのタイトルも表示したいと思います。私はそれを取得する方法がわかりません。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSMutableArray *sectionArray = [self.arrayOfSections objectAtIndex:indexPath.section];
UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
NSString *cellText = selectedCell.textLabel.text;
NSLog(@"Selected Cell: %@", cellText);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Selected a row" message:[sectionArray objectAtIndex:indexPath.row] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
- (NSString *) tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
NSString *result = nil;
if ([tableView isEqual:self.myTableView] && section == 0) {
myTableView.tableHeaderView.tag = FROZEN;
result = @"Frozen";
} else if ([tableView isEqual:self.myTableView] && section == 1) {
myTableView.tableHeaderView.tag = FRUIT;
result = @"Fruit";
}
else if ([tableView isEqual:self.myTableView] && section == 2) {
myTableView.tableHeaderView.tag = SALADS;
result = @"Salads";
} else if ([tableView isEqual:self.myTableView] && section == 3) {
myTableView.tableHeaderView.tag = VEGETABLES;
result = @"Vegetables";
}
return result;
}