好的,所以我在这个函数中写了一些代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
NSLog(@"tableviwcell is getting called");
properties = [NSUserDefaults standardUserDefaults];
NSDictionary *events_dict = [properties objectForKey:@"events_dict"];
NSDictionary *events = [events_dict objectForKey:@"event"];
am_participants = [events objectForKey:@"amParticipants"];
pm_participants = [events objectForKey:@"pmParticipants"];
UITableViewCell *cell = nil;
cell = [tableView dequeueReusableCellWithIdentifier:@"currentCell"];
if(cell == nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"currentCell"];
}
int sizeofam = [am_participants count];
int sizeofpm = [pm_participants count];
NSMutableArray *participants =[[NSMutableArray alloc] init];
NSLog(@"size of am: %i", sizeofam);
if(sizeofam > 0 && sizeofpm > 0){
for(int i = 0; i < sizeofam; i++){
NSDictionary *ampart_dict = [am_participants objectAtIndex:i];
NSString *ampart_email = [ampart_dict objectForKey:@"email"];
NSString *ampart_email_extra = [@"am" stringByAppendingString:ampart_email];
[participants addObject:ampart_dict];
}
for(int i = 0; i < sizeofpm; i++){
NSDictionary *pmpart_dict = [pm_participants objectAtIndex:i];
NSString *pmpart_email = [pmpart_dict objectForKey:@"email"];
NSString *pmpart_email_extra = [@"pm" stringByAppendingString:pmpart_email];
[participants addObject:pmpart_dict];
NSLog(@"%@", participants);
}
int sizeofparticipants = [participants count];
for(int i = 0; i < sizeofparticipants; i++){
NSString *participanti = [[participants objectAtIndex:i] objectForKey:@"email"];
for(int j = 0; j < sizeofparticipants; j++){
NSString *participantj = [[participants objectAtIndex:j] objectForKey:@"email"];
if([participanti isEqualToString:participantj]){
NSLog(@"Participant j: %@", participantj);
[participants removeObjectAtIndex:j];
sizeofparticipants = [participants count];
}
}
}
基本上我需要将两个数组 am_participants 和 pm_participants 合并到一个参与者数组中。数组中的每个对象都是一个字典,其中包含各种值,例如姓名、电子邮件等。然后我必须从列表中删除任何重复的值(例如,如果有人在 am 列表和 pm 列表中。我通过删除来做到这一点如果他们的电子邮件地址在任一列表中相同,则值。
在此之后,我需要通过使用参与者列表填充单元格来在一个列表中显示名为“参与者”的新参与者数组。
我已将单元格数设置为 30。
然而,当向下滚动列表时,单元格会随机填充不同的名称,因为认为数组位置正在移动以及出现重复值。
有人可以解释我做错了什么吗?
谢谢!