From 767a762f2c220527762f3c59fd0aeb12ccd474ec Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sat, 20 Mar 2021 00:13:49 +0300 Subject: Fix text input view in chat on Mac --- Juick/ViewControllers/ChatViewController.m | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'Juick/ViewControllers/ChatViewController.m') 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]; }]; } -- cgit v1.2.3