tags:

views:

181

answers:

2

hi guys , im having a problem with setting my section headers in a uitableview, its probably something really simple i just cant work it out.

instead of displaying different headers for different sections it displays the same header for each section

help me please :)

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    WorldCupAppDelegate *appDelegate = [UIApplication sharedApplication].delegate;

    return [appDelegate.matchFixtures count];
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {


    WorldCupAppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
    Fixtures *fixtures = [appDelegate.matchFixtures objectAtIndex:section];

    return fixtures.matchDate;

}
+1  A: 

Try like this

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:      (NSInteger)section {
NSString *title = nil;
// Return a title or nil as appropriate for the section.
switch (section) {
    case 0:
        title = [[appDelegate.matchFixtures objectAtIndex:section]matchDate];
        break;
    case 1:
        title = [[appDelegate.matchFixtures objectAtIndex:section]matchDate];
        break;
    case 2:
        title = [[appDelegate.matchFixtures objectAtIndex:section]matchDate];
        break;
    default:
        break;
}
return title;
 }

Edit

Set the date properly with retain in the delegate class.Even i had some problems similar when storing values in delegates.

- (void)setCurrentDates:(NSString *)value {
[value retain]; // <- Retain new value
[date release]; // <- Release old value;
date = value;
}

All the best.

Warrior
that looks about right , but it crashes my app with2010-04-29 14:25:51.729 WorldCup[4912:207] *** -[Fixtures length]: unrecognized selector sent to instance 0x3b0fe302010-04-29 14:25:51.730 WorldCup[4912:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[Fixtures length]: unrecognized selector sent to instance 0x3b0fe30'2010-04-29 14:25:51.731 WorldCup[4912:207] Stack: (any ideas why?
richard Stephenson
print and check any one date value getting from the delegate
Warrior
Based on the code in your question, the code in this answer should read case 0: title = [[appDelegate.matchFixtures objectAtIndex:section] matchDate];
Don McCaughey
thanks for all your help , unfortunatly i still couldn't get it working , so have gone a different way around it
richard Stephenson
+3  A: 

Your original code looks okay. I'm betting that appDelegate.matchFixtures doesn't contain the data you think it does. Modify your code to look like this:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  WorldCupAppDelegate *appDelegate = [UIApplication sharedApplication].delegate;

  NSLog(@"appDelegate.matchFixtures.count = %i", appDelegate.matchFixtures.count);

  return [appDelegate.matchFixtures count];
}

- (NSString *)tableView:(UITableView *)tableView 
titleForHeaderInSection:(NSInteger)section {

  WorldCupAppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
  Fixtures *fixtures = [appDelegate.matchFixtures objectAtIndex:section];

  NSLog(@"For section %i, fixtures.matchDate = %@", section, fixtures.matchDate);

  return fixtures.matchDate;
}

And look at the log output in the debug console.

Don McCaughey