From 89fe31e71e4d22108bd39d9afa69929dccfab9ba Mon Sep 17 00:00:00 2001 From: Jesse Squires Date: Sat, 23 Mar 2013 18:42:11 -0400 Subject: [PATCH] updated demo --- MessagesDemo/DemoViewController.h | 2 +- MessagesDemo/DemoViewController.m | 55 +++++++++++++++++-------------- 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/MessagesDemo/DemoViewController.h b/MessagesDemo/DemoViewController.h index dfd1b1d..2069a3c 100644 --- a/MessagesDemo/DemoViewController.h +++ b/MessagesDemo/DemoViewController.h @@ -28,7 +28,7 @@ #import "JSMessagesViewController.h" -@interface DemoViewController : JSMessagesViewController +@interface DemoViewController : JSMessagesViewController @property (strong, nonatomic) NSMutableArray *messages; @property (strong, nonatomic) NSMutableArray *timestamps; diff --git a/MessagesDemo/DemoViewController.m b/MessagesDemo/DemoViewController.m index bfe94dc..d870279 100644 --- a/MessagesDemo/DemoViewController.m +++ b/MessagesDemo/DemoViewController.m @@ -39,11 +39,11 @@ - (void)viewDidLoad { [super viewDidLoad]; + self.delegate = self; + self.dataSource = self; self.title = @"Messages"; - self.timestampPolicy = JSMessagesViewTimestampPolicyEveryThree; - self.messages = [[NSMutableArray alloc] initWithObjects: @"Testing some messages here.", @"This work is based on Sam Soffes' SSMessagesViewController.", @@ -65,29 +65,7 @@ return self.messages.count; } -#pragma mark - Messages view controller -- (JSBubbleMessageStyle)messageStyleForRowAtIndexPath:(NSIndexPath *)indexPath -{ - return (indexPath.row % 2) ? JSBubbleMessageStyleIncomingDefault : JSBubbleMessageStyleOutgoingDefault; -} - -- (NSString *)textForRowAtIndexPath:(NSIndexPath *)indexPath -{ - return [self.messages objectAtIndex:indexPath.row]; -} - -- (NSDate *)timestampForRowAtIndexPath:(NSIndexPath *)indexPath -{ - return [self.timestamps objectAtIndex:indexPath.row]; -} - -- (BOOL)shouldHaveTimestampForRowAtIndexPath:(NSIndexPath *)indexPath -{ - // Override here if using JSMessagesViewTimestampPolicyCustom - - return [super shouldHaveTimestampForRowAtIndexPath:indexPath]; -} - +#pragma mark - Messages view delegate - (void)sendPressed:(UIButton *)sender withText:(NSString *)text { [self.messages addObject:text]; @@ -102,4 +80,31 @@ [self finishSend]; } +- (JSBubbleMessageStyle)messageStyleForRowAtIndexPath:(NSIndexPath *)indexPath +{ + return (indexPath.row % 2) ? JSBubbleMessageStyleIncomingSquare : JSBubbleMessageStyleOutgoingSquare; +} + +- (JSMessagesViewTimestampPolicy)timestampPolicyForMessagesView +{ + return JSMessagesViewTimestampPolicyEveryThree; +} + +- (BOOL)hasTimestampForRowAtIndexPath:(NSIndexPath *)indexPath +{ + // custom implementation here, if using `JSMessagesViewTimestampPolicyCustom` + return [self shouldHaveTimestampForRowAtIndexPath:indexPath]; +} + +#pragma mark - Messages view datasource +- (NSString *)textForRowAtIndexPath:(NSIndexPath *)indexPath +{ + return [self.messages objectAtIndex:indexPath.row]; +} + +- (NSDate *)timestampForRowAtIndexPath:(NSIndexPath *)indexPath +{ + return [self.timestamps objectAtIndex:indexPath.row]; +} + @end \ No newline at end of file