summaryrefslogtreecommitdiff
path: root/Juick/ViewControllers
diff options
context:
space:
mode:
Diffstat (limited to 'Juick/ViewControllers')
-rw-r--r--Juick/ViewControllers/ChatViewController.h4
-rw-r--r--Juick/ViewControllers/ChatViewController.m23
2 files changed, 18 insertions, 9 deletions
diff --git a/Juick/ViewControllers/ChatViewController.h b/Juick/ViewControllers/ChatViewController.h
index bfd63e7..f21eb10 100644
--- a/Juick/ViewControllers/ChatViewController.h
+++ b/Juick/ViewControllers/ChatViewController.h
@@ -10,9 +10,11 @@
#import "User.h"
#import "MessageInputView.h"
-@interface ChatViewController : UITableViewController<MessageInputDelegate>
+@interface ChatViewController : UIViewController<MessageInputDelegate, UITableViewDelegate, UITableViewDataSource>
@property(nonatomic, strong) NSMutableArray *messages;
@property(nonatomic, strong) NSString *uname;
+@property (weak, nonatomic) IBOutlet UIStackView *stack;
+@property (strong, nonatomic) IBOutlet UITableView *tableView;
-(void) reloadChat;
@end
diff --git a/Juick/ViewControllers/ChatViewController.m b/Juick/ViewControllers/ChatViewController.m
index 695d7ec..9493155 100644
--- a/Juick/ViewControllers/ChatViewController.m
+++ b/Juick/ViewControllers/ChatViewController.m
@@ -23,6 +23,8 @@
- (void)viewDidLoad {
[super viewDidLoad];
[self.navigationController.visibleViewController setTitle:self.uname];
+ self.tableView.delegate = self;
+ self.tableView.dataSource = self;
[self.tableView registerNib:[UINib nibWithNibName:@"BubbleMessageCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"bubbleMessageCell"];
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeInteractive;
@@ -30,9 +32,12 @@
self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAutomatic;
[self reloadChat];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
- self.refreshControl = [UIRefreshControl new];
- [self.refreshControl addTarget:self action:@selector(reloadChat) forControlEvents:UIControlEventValueChanged];
+ self.tableView.refreshControl = [UIRefreshControl new];
+ [self.tableView.refreshControl addTarget:self action:@selector(reloadChat) forControlEvents:UIControlEventValueChanged];
[self addObserver:self forKeyPath:@"uname" options:0 context:nil];
+#if TARGET_OS_MACCATALYST
+ [self.stack addArrangedSubview:[self inputAccessoryView]];
+#endif
}
-(void) reloadChat {
@@ -42,18 +47,20 @@
if (err == nil) {
[self.messages addObjectsFromArray:[[messages reverseObjectEnumerator] allObjects]];
NSMutableArray *indexPaths = [NSMutableArray new];
- for (NSUInteger index = 0; index < [messages count]; index++) {
+ NSInteger messagesCount = [self.messages count];
+ for (NSUInteger index = 0; index < messagesCount; index++) {
[indexPaths addObject:[NSIndexPath indexPathForRow:index inSection: 0]];
}
- [self.tableView beginUpdates];
- [self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:YES];
- [self.tableView endUpdates];
- NSInteger messagesCount = [self.messages count];
+ if (indexPaths > 0) {
+ [self.tableView beginUpdates];
+ [self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:YES];
+ [self.tableView endUpdates];
+ }
if (messagesCount > 0) {
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:[self.messages count]-1 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:NO];
}
}
- [self.refreshControl endRefreshing];
+ [self.tableView.refreshControl endRefreshing];
}];
}