2010-04-29 5 views
0

메신저 섹션 헤더를 uitableview에 설정하는 데 문제가 있습니다. 그게 뭔가 정말 간단합니다. 대신 다른 부분에 대해 서로 다른 헤더를 표시UITableView의 섹션 헤더에 문제가 있습니다

은 나를

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

} 
+0

appDelegate.matchFixtures 카운트가 NSLog?를 통해 인쇄하여 어떤 가치가 있는지 확인 했습니까? fixtures.matchDate와 동일합니까? –

+0

모든 matchFixture에는 다른 matchDate가 있습니까? – DyingCactus

답변

1

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

편집

같은 시도 :)하십시오 각 섹션

도움을 같은 헤더를 표시

델리게이트 클래스에서 retain을 사용하여 날짜를 올바르게 설정합니다. 대리자에 값을 저장할 때 비슷한 문제가있었습니다.

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

모두 최고입니다.

+0

제대로 보이지만 내 응용 프로그램이 작동하지 않습니다 2010-04-29 14 : 25 : 51.729 WorldCup [4912 : 207] *** - [Fixtures length] : 인스턴스로 전송 된 알 수없는 선택자 0x3b0fe30 2010-04 -27 14 : 25 : 51.730 WorldCup [4912 : 207] *** 캐치되지 않은 예외 'NSInvalidArgumentException'으로 인해 앱 종료 중, 이유 : '*** - [Fixtures length] : 인스턴스 0x3b0fe30로 전송 된 인식 할 수없는 선택자' 2010-04- 2934 14 : 25 : 51.731 WorldCup [4912 : 207] Stack : ( 이유가 무엇입니까? –

+0

인쇄하여 위임자로부터 날짜 값 하나를 확인하십시오. – Warrior

+0

질문에있는 코드를 기반으로이 대답의 코드는 대소 문자를 읽어야합니다 0 : title = [[appDelegate.matchFixtures objectAtIndex : section] matchDate]; –

3

원본 코드는 괜찮아 보입니다. 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; 
} 

디버그 콘솔에서 로그 출력을 확인하십시오.

관련 문제