2013-04-03 2 views
2

NSMutableArrayNSMutableDictionary 사용하여 문제가 있습니다.NSMutableArray 및 NSMutableDictionary있는 TableView

나는 멈출 때 현재 점수와 날짜를 tableview에 표시해야한다는 퀴즈를 만들었습니다. 그런 다음 해당 값을 tableview에 표시해야합니다. 그러나 아무 것도 그것의 viewController을로드 할 때 tableview에 표시됩니다. mutableArrayviewDidLoad: 방법으로 만들어집니다. 내 코드가 맞습니까? 아니면 여기에 뭔가 빠졌습니까?

- (IBAction)saveResult:(id)sender { 

    dateFormatter = [[NSDateFormatter alloc] init]; 
    [dateFormatter setDateFormat:NSLocalizedString(@"DATE", nil)];// @"HH:mm zz"]; 

    dateNow = [NSDate date]; 
    NSString *formattedDateString = [dateFormatter stringFromDate:dateNow]; 


    // Add the quiz result to the array, reload the data in the tableview 
    highscoreAndDate = [NSMutableDictionary dictionaryWithObjectsAndKeys: 
          [NSString stringWithFormat:@"%i points", score], @"kResult", 
          formattedDateString, @"kDate", nil]; 

    [highscore addObject:highscoreAndDate]; 

    [tableView reloadData]; 
} 

내있는 tableView 방법 :

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 

    return 1; 

} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 

    return [highscore count]; 
} 

- (UITableViewCell *)tableView:(UITableView *)_tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 

     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; 

    } 

    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; 
    [dateFormat setDateFormat: @"HH:mm zz"]; 

    cell.detailTextLabel.text = [[highscore objectAtIndex:indexPath.row] objectForKey:@"kResult"]; 

    cell.detailTextLabel.text = [[highscore objectAtIndex:indexPath.row] objectForKey:@"kDate"]; 

    return cell; 
} 
+0

보기 내가보기 않았다로드 방법. – Balu

+0

이것은 Xcode에 대한 질문이 아닙니다. –

+0

cellForRowAtIndexPath에 중단 점을 넣고 실행되는지 확인 하시겠습니까 ?? 실행되지 않으면 viewWillAppear 메서드에 논리를 넣어 :) – iPatel

답변

0

@Anoop Vaidya.

나는 옳은 길로 가야합니다. NSLog 문을 개체를 추가 할 때 넣어 및 내 배열의 행 개수가 올라가고 보여줍니다. 그래서 내 코드가 맞습니다.

나는 그것이 내 XIB 파일 (매우 당황 스럽다!)에서의 나의 연결 때문인 것으로 알았다. 내 자신을 발견 했어야 했어. 잘못된 viewController에 대한 내 tableview 콘센트를 연결했기 때문에 tableview는 절대로 채워지지 않았습니다.

너무 빨리 답변 해 주신 모든 분들께 감사 드리며 감사드립니다. 다행 이군. :)

관련 문제