0

Firstly, I return hello as the section title.And I want to change the section title to "hi" after I click a custom button? How to toggle the titleForHeadInsection method?

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    return @"hello";
}
Grzegorz Krukowski
  • 18,081
  • 5
  • 50
  • 71
seguedestination
  • 419
  • 4
  • 19

2 Answers2

0

Simplest is to reload whole table:

[tableView reloadData]

More optimize version will reload a given section only, but you probably not at the stage of optimizing yet.

Grzegorz Krukowski
  • 18,081
  • 5
  • 50
  • 71
  • hhhhhh…. I really want to take the optimizing method….Because my project have many insert rows, and delete rows options… I just ask the question by a simple example – seguedestination Jun 21 '15 at 09:37
0

Store the section title in a property in your UIViewController, or whatever class is acting as your UITableViewDelegate.

@property (nonatomic,strong) NSString *sectionTitle;

And set its value to @"hello" somewhere. Then when in your button press method, update self.sectionTitle with the new title.

self.sectionTitle = @"hi";

Then reload your entire UITableView or reload the appropriate section.

[tableView reloadData]; // Entire

Or

NSIndexSet *sectionIndex = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 1)];                                     
[self.tableView reloadSections:section withRowAnimation: UITableViewRowAnimationAutomatic]; 
// Specific section
Tim
  • 8,932
  • 4
  • 43
  • 64