summaryrefslogtreecommitdiff
path: root/Juick/ViewControllers/MessagesViewController.m
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2019-03-26 10:27:45 +0300
committerGravatar Vitaly Takmazov2019-03-26 10:27:45 +0300
commit38f90aa20adfa5fc346dda3cc151fa68bf2f6a5d (patch)
tree426423f236c069cc6878f0543cb857ec7efef829 /Juick/ViewControllers/MessagesViewController.m
parent4efd5ac3d91c5880c5acab78d01a003ad6bbcd86 (diff)
Fix crashes
Diffstat (limited to 'Juick/ViewControllers/MessagesViewController.m')
-rw-r--r--Juick/ViewControllers/MessagesViewController.m9
1 files changed, 6 insertions, 3 deletions
diff --git a/Juick/ViewControllers/MessagesViewController.m b/Juick/ViewControllers/MessagesViewController.m
index 5d47d01..f2a20a9 100644
--- a/Juick/ViewControllers/MessagesViewController.m
+++ b/Juick/ViewControllers/MessagesViewController.m
@@ -70,9 +70,12 @@ NSString* const messageCellIdentifier = @"messageCell";
[self.tableView endUpdates];
[self.refreshControl endRefreshing];
if (self.shouldScrollToUnreadOnRefresh) {
- NSInteger itemToScroll = [self.firstUnread integerValue] ? : self.messages.count - 1;
- NSIndexPath *lastRow = [NSIndexPath indexPathForRow:itemToScroll inSection:0];
- [self.tableView scrollToRowAtIndexPath:lastRow atScrollPosition:UITableViewScrollPositionBottom animated:NO];
+ NSInteger messagesCount = [self.messages count];
+ if (messagesCount > 0) {
+ NSInteger itemToScroll = [self.firstUnread integerValue] ? : self.messages.count - 1;
+ NSIndexPath *lastRow = [NSIndexPath indexPathForRow:MIN(itemToScroll, messagesCount) inSection:0];
+ [self.tableView scrollToRowAtIndexPath:lastRow atScrollPosition:UITableViewScrollPositionBottom animated:NO];
+ }
self.firstUnread = nil;
}
}];