cant display messages based on date of the data.
iTroyd23 opened this issue · 0 comments
iTroyd23 commented
if we set snap interval, messages display based snapinterval. how to list out the message based on the data's date
update: replace the below method in uibubbletableview:
-
(void)reloadData
{
self.showsVerticalScrollIndicator = NO;
self.showsHorizontalScrollIndicator = NO;// Cleaning up
self.bubbleSection = nil;// Loading new data
int count = 0;if !__has_feature(objc_arc)
self.bubbleSection = [[[NSMutableArray alloc] init] autorelease];
else
self.bubbleSection = [[NSMutableArray alloc] init];
endif
if (self.bubbleDataSource && (count = [self.bubbleDataSource rowsForBubbleTable:self]) > 0)
{if !__has_feature(objc_arc)
NSMutableArray *bubbleData = [[[NSMutableArray alloc] initWithCapacity:count] autorelease];
else
NSMutableArray *bubbleData = [[NSMutableArray alloc] initWithCapacity:count];
endif
for (int i = 0; i < count; i++) { NSObject *object = [self.bubbleDataSource bubbleTableView:self dataForRow:i]; assert([object isKindOfClass:[NSBubbleData class]]); [bubbleData addObject:object]; } [bubbleData sortUsingComparator:^NSComparisonResult(id obj1, id obj2) { NSBubbleData *bubbleData1 = (NSBubbleData *)obj1; NSBubbleData *bubbleData2 = (NSBubbleData *)obj2; return [bubbleData1.date compare:bubbleData2.date]; }]; NSMutableArray *currentSection = nil; NSMutableArray * datesArray = [[NSMutableArray alloc]init]; for (int i = 0; i < count; i++) { NSBubbleData *data = (NSBubbleData *)[bubbleData objectAtIndex:i]; NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]]; [dateFormat setDateFormat:@"MMMM d, yyyy"]; NSString* timeString =[dateFormat stringFromDate:data.date]; if(![datesArray containsObject:timeString]) { [datesArray addObject:timeString]; } } for (int j = 0; j <[datesArray count]; j++) { currentSection = [[NSMutableArray alloc] init]; for (int i = 0; i < count; i++) { NSBubbleData *data = (NSBubbleData *)[bubbleData objectAtIndex:i]; NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]]; [dateFormat setDateFormat:@"MMMM d, yyyy"]; NSString* timeString =[dateFormat stringFromDate:data.date]; if ([timeString isEqualToString:[datesArray objectAtIndex:j]]) { [currentSection addObject:data]; } } [self.bubbleSection addObject:currentSection]; }
}
[super reloadData];
}