Iphone UITableView中的节标题有问题

Iphone UITableView中的节标题有问题,iphone,Iphone,我在uitableview中设置我的分区标题时遇到了一个问题,这可能很简单,我就是无法解决 它不会为不同的节显示不同的标题,而是为每个节显示相同的标题 请帮帮我:) 像这样试试 - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection: (NSInteger)section { NSString *title = nil; // Return a title or nil as appropriat

我在uitableview中设置我的分区标题时遇到了一个问题,这可能很简单,我就是无法解决

它不会为不同的节显示不同的标题,而是为每个节显示相同的标题

请帮帮我:)

像这样试试

- (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;
 }
编辑

在delegate类中使用retain正确设置日期。即使是我在delegate中存储值时也遇到了类似的问题

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

- (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;
 }
编辑

在delegate类中使用retain正确设置日期。即使是我在delegate中存储值时也遇到了类似的问题

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

[value retain];//您的原始代码看起来不错。我打赌appDelegate.matchFixtures不包含您认为它包含的数据。请修改您的代码,使其看起来像这样:

- (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;
}

然后查看调试控制台中的日志输出。

您的原始代码看起来不错。我打赌appDelegate.matchFixtures不包含您认为它包含的数据。请修改代码,使其看起来像这样:

- (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;
}

然后查看调试控制台中的日志输出。

是否通过NSLog打印检查appDelegate.matchFixtures count是否有任何值?fixtures.matchDate是否相同?每个matchFixture是否有不同的matchDate?是否通过NSLog打印检查appDelegate.matchFixtures count是否有任何值?Fixture是否相同es.matchDate?每个matchFixture都有不同的matchDate吗?看起来不错,但它使我的应用程序崩溃,导致2010-04-29 14:25:51.729世界杯[4912:207]***-[Fixtures length]:未识别的选择器发送到实例0x3b0fe30 2010-04-29 14:25:51.730世界杯[4912:207]***由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:'***-[Fixtures length]:未识别的选择器发送到实例0x3b0fe30'2010-04-29 14:25:51.731 WorldCup[4912:207]堆栈:(有什么想法吗?打印并检查从委托人处获得的任何一个日期值基于问题中的代码,此答案中的代码应为案例0:title=[[appDelegate.matchFixtures objectAtIndex:section]matchDate];感谢您的帮助,不幸的是,我仍然无法让它工作,所以我采取了另一种看起来正确的方法,但它使我的应用程序在2010-04-29 14:25:51.729世界杯[4912:207]***-[Fixtures length]:未识别的选择器发送到实例0x3b0fe30 2010-04-29 14:25:51.730世界杯[4912:207]***由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:'***-[Fixtures length]:未识别的选择器发送到实例0x3b0fe30'2010-04-29 14:25:51.731 WorldCup[4912:207]堆栈:(有什么想法吗?根据问题中的代码,打印并检查从委托人处获得的任何一个日期值,此答案中的代码应为案例0:title=[[appDelegate.matchFixtures objectAtIndex:section]matchDate];感谢您的所有帮助,不幸的是,我仍然无法让它工作,因此我们采取了不同的方法解决它