NSArray和NSDictionary添加重复的对象



将对象添加到NSArray或NSDictionary时,我的应用程序只显示上一个条目的副本。

我获取数据并将其发送给观察员。。。

    [[NSNotificationCenter defaultCenter] postNotificationName:@"xmlFinishedLoading" object:self userInfo:[NSDictionary dictionaryWithObject:currentEventObject forKey:@"notifKey"]];

此代码在observer收到通知时运行。。。

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

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的条目,它会显示相同的条目。有什么帮助吗?

更多的包含代码会很有帮助,你所拥有的对我来说很好。这个代码出现在什么方法中?每次你带着userInfo对象回来填充self.eventDictionary时,它是否可能被删除?

最新更新