I want to remove UITableViewCells from my TableView if the userName "Brittany" appears more than once in my NSMutableArray. E.g. only the first cell displaying userName "Brittany" should appear. If my array self.messages contains userName "Brittany" more than once, I only want to show the first cell. How can I do this? See code below so far:
ViewController.m
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *PointsTableIdentifier = @"MyMessagesCell";
MyMessagesCell *cell = (MyMessagesCell *)[tableView dequeueReusableCellWithIdentifier:PointsTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"MyMessagesCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
NSMutableArray* NameDictionary=[[NSMutableArray alloc] init];
NSString* PreviousName;
int oneTime=0;
for(int i=0;i<[self.messages count];i++){
NSDictionary *fromUser = [self.messages objectAtIndex: i];
NSString *userName = [fromUser objectForKey:@"name"];
if(oneTime==0)
{
NSLog(@"TEST!");
PreviousName=userName;
[NameDictionary addObject:[self.messages objectAtIndex: i]];
oneTime=1;
}
if(oneTime!=0)
{
if([PreviousName isEqualToString: userName])
{
NSLog(@"TEST 1!");
}
else{
[NameDictionary addObject:[self.messages objectAtIndex: i]];
NSLog(@"TEST 2!");
}
PreviousName=userName;
}
}
}
NSDictionary *receivedSubjectLine = [self.messages objectAtIndex:indexPath.row];
NSString *messageSubject = [receivedSubjectLine objectForKey:@"node_title"];
[cell.subjectLine setText:messageSubject];
NSDictionary *fromUser = [self.messages objectAtIndex:indexPath.row];
NSString *userName = [fromUser objectForKey:@"name"];
[cell.senderName setText:userName];
NSDictionary *receivedBody = [self.messages objectAtIndex:indexPath.row];
NSString *messageBody = [receivedBody objectForKey:@"body"];
[cell.fullMessage setText:messageBody];
NSDictionary *messageReceived = [self.messages objectAtIndex:indexPath.row];
NSString *timeReceived = [messageReceived objectForKey:@"published at"];
NSLog(@"Message Received at %@", timeReceived);
[cell.receivedStamp setText:timeReceived];
return cell;
}