From 2054659f8f33421675f48c0a76fb426ce114e15a Mon Sep 17 00:00:00 2001 From: David Idmansour Date: Mon, 2 Jul 2018 10:35:01 +0200 Subject: [PATCH] static view dimensions & scroll to bottom when new message received --- .../NotificationViewController.m | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/richNotifications/NotificationViewController.m b/richNotifications/NotificationViewController.m index 99807e97c..0fb12407e 100644 --- a/richNotifications/NotificationViewController.m +++ b/richNotifications/NotificationViewController.m @@ -26,28 +26,27 @@ } - (void)didReceiveNotification:(UNNotification *)notification { - static float initialHeight = -1; - if (initialHeight < 0) - initialHeight = self.tableView.frame.size.height; - printf("Initial height : %f\n", initialHeight); +// static float initialHeight = -1; +// if (initialHeight < 0) +// initialHeight = self.tableView.frame.size.height; if (msgs) [msgs addObject:[((NSArray *)[[[[notification request] content] userInfo] objectForKey:@"msgs"]) lastObject]]; else msgs = [NSMutableArray arrayWithArray:[[[[notification request] content] userInfo] objectForKey:@"msgs"]]; [self.tableView reloadData]; - float height = 0; - for (int i = 0 ; i < self->msgs.count ; i++) { - height += [self tableView:self.tableView heightForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]]; - } - if (height > initialHeight) { - CGRect frame = self.tableView.frame; - frame.size.height = height; - frame.origin = CGPointMake(0, 0); - self.tableView.frame = frame; - self.tableView.bounds = frame; - self.preferredContentSize = CGSizeMake(self.preferredContentSize.width, height); - } - printf("Height : %f\n", height); + [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:msgs.count - 1 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:YES]; +// float height = 0; +// for (int i = 0 ; i < self->msgs.count ; i++) { +// height += [self tableView:self.tableView heightForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]]; +// } +// if (height > initialHeight) { +// CGRect frame = self.tableView.frame; +// frame.size.height = height; +// frame.origin = CGPointMake(0, 0); +// self.tableView.frame = frame; +// self.tableView.bounds = frame; +// self.preferredContentSize = CGSizeMake(self.preferredContentSize.width, height); +// } NSLog(@"Content length : %f", self.tableView.contentSize.height); NSLog(@"Number of rows : %d", (unsigned int)[self tableView:self.tableView numberOfRowsInSection:0]); NSLog(@"View bounds length : %f", self.tableView.bounds.size.height);