0
NSArray 또는 NSDictionary에 객체를 추가 할 때 내 응용 프로그램은 마지막 항목의 복제본 만 표시합니다.NSArray 및 NSDictionary 중복 객체를 추가합니다.
나는
-(void)populateCurrentEventsTableView:(NSDictionary *)events
{
NSDictionary *info = [events valueForKey:@"userInfo"];
Event *evt = [info valueForKey:@"notifKey"];
if (self.eventDictionary == nil) {
self.eventDictionary = [[NSMutableDictionary alloc]init];
}
[self.eventList addObject:evt];
NSString *key = [NSString stringWithFormat:@"%i",[eventList count] - 1];
[self.eventDictionary setValue:evt forKey:key];
NSLog(@"events description = %@",evt.eventDescription);
[self.tableView reloadData];
}
[[NSNotificationCenter defaultCenter] postNotificationName:@"xmlFinishedLoading" object:self userInfo:[NSDictionary dictionaryWithObject:currentEventObject forKey:@"notifKey"]];
관찰자가 통지를받을 때이 코드가 실행됩니다 ...있는 TableView이 코드를 다시로드 ... 데이터를 얻을 관찰자로 보내 ...
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"ActivitiesList";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell...
NSUInteger row = [indexPath row];
NSString *rowKey = [NSString stringWithFormat:@"%i",row];
Event *evt = [eventDictionary objectForKey:rowKey];
cell.textLabel.text = evt.eventDescription;
cell.detailTextLabel.text = evt.eventSecondaryDescription;
return cell;
}
,이벤트 설명을 표시하는 NSLog는 올 때마다 다른 항목을 표시합니다. 그러나 eventDictionary의 항목을 표시하려면 동일한 항목이 표시됩니다. 어떤 도움이 필요합니까?
몇 가지 코드를 추가했습니다. 잘하면 표시됩니다. – cohs
"동일한 항목을 보여줍니다"라는 의미는 무엇입니까? eventDictionary 하나의 항목 만 길거나 올바른 항목 수 (추가하려는 항목 수)가 n 항목 각각 모두 동일합니까? –