2012-01-24 10 views
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"]]; 

観察者が通知を受信したときにこのコードが実行される...テーブルビューは、このコードを再ロード...データを取得し、観察者にそれを送信します...

- (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のエントリを表示すると、同じエントリが表示されます。どんな助け?

答えて

0

その他のコードが含まれていると便利です。このコードはどのような方法で表示されますか? userInfoオブジェクトを埋め込むたびにself.eventDictionaryが消去される可能性はありますか?

+0

もう少しコードを追加しました。うまくいけば何かを表示します。 – cohs

+0

「同じエントリーを表示しています」とはどういう意味ですか? eventDictionaryは1項目だけですか、それとも正しい項目数(追加しようとした項目の数)ですか?n項目はすべて同じですか? –

関連する問題