UPDATE : Sorry,previous code content some bugs with section reusability,please use the new code:
1.remove lastNotificationTitle and lastNotificationSection, add NSMutableDictionary * notificationTitlesDic
2.chang somethingHappens: and configureHeaderSectionWithString: with the code:
-(void) somethingHappens:(NSNotification*) notification
{
NSLog(@"Notification %@", notification);
NSDictionary *notificationDic = notification.object;
NSString *title = [notificationDic valueForKey:@"title"];
NSIndexPath *indexPath = [notificationDic objectForKey:@"index"];
[self.notificationTitlesDic setObject:title forKey:[NSString stringWithFormat:@"%d",indexPath.section]];
if(self.section == indexPath.section){
textLabel.text = title;
}
}
-(void)configureHeaderSectionWithString:(NSString *) text andSection:(NSInteger)section
{
NSString * targetKey = [NSString stringWithFormat:@"%d",section];
for (NSString * key in self.notificationTitlesDic) {
if([targetKey isEqualToString:key]){
textLabel.text = [self.notificationTitlesDic valueForKey:key];
return;
}
}
textLabel.text = text;
}
have a test with my testless code :]