mirror of
https://github.com/zhigang1992/MessagesTableViewController.git
synced 2026-06-13 01:18:06 +08:00
updated demo
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user