NSMutableArray
및 NSMutableDictionary
사용하여 문제가 있습니다.NSMutableArray 및 NSMutableDictionary있는 TableView
나는 멈출 때 현재 점수와 날짜를 tableview
에 표시해야한다는 퀴즈를 만들었습니다. 그런 다음 해당 값을 tableview
에 표시해야합니다. 그러나 아무 것도 그것의 viewController
을로드 할 때 tableview에 표시됩니다. mutableArray
은 viewDidLoad:
방법으로 만들어집니다. 내 코드가 맞습니까? 아니면 여기에 뭔가 빠졌습니까?
- (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;
}
보기 내가보기 않았다로드 방법. – Balu
이것은 Xcode에 대한 질문이 아닙니다. –
cellForRowAtIndexPath에 중단 점을 넣고 실행되는지 확인 하시겠습니까 ?? 실행되지 않으면 viewWillAppear 메서드에 논리를 넣어 :) – iPatel