updated demo

This commit is contained in:
Jesse Squires
2013-03-23 18:42:11 -04:00
parent 81fe042f2d
commit 89fe31e71e
2 changed files with 31 additions and 26 deletions

View File

@@ -28,7 +28,7 @@
#import "JSMessagesViewController.h"
@interface DemoViewController : JSMessagesViewController
@interface DemoViewController : JSMessagesViewController <JSMessagesViewDelegate, JSMessagesViewDataSource>
@property (strong, nonatomic) NSMutableArray *messages;
@property (strong, nonatomic) NSMutableArray *timestamps;

View File

@@ -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