读取UITableView Section Title的字符串值

Lau*_*ell 2 xcode uitableview sectionheader

我想将UITableView的节标题推送到另一个视图控制器的节标题.但我无法找到一种方法来阅读现有的部分标题.现有的节标题是动态构造的,我宁愿重复使用它而不是重新构建它.

 if (indexPath.section == 0) {

      SecondViewController *secondViewController = [[SecondViewController alloc] init];
      secondViewController.strValueHolder = FOO_section.sectionTitle; // FOO Code
      [[self navigationController] pushViewController:secondViewController animated:YES];
      [secondViewController release];

 }
Run Code Online (Sandbox Code Playgroud)

小智 8

您可以直接调用titleForHeaderInSection方法:

NSString *sectionTitle = 
    [self tableView:tableView titleForHeaderInSection:indexPath.section];
Run Code Online (Sandbox Code Playgroud)

或者将titleForHeaderInSection中当前拥有的代码移动到自定义方法,并从titleForHeaderInSection和您要推送另一个视图控制器的位置调用该自定义方法.