2016-04-02 4 views
1

Ich habe einen Chat-Bildschirm mit UITableView gebaut. Ich möchte bis zum Ende von UITableView scrollen, der Moment, in dem der Bildschirm von einem anderen View-Controller geöffnet wird. Mit trivial scroll to bottom Funktionen, zeigt einen Ruck, wenn der Chat lang ist. Gibt es eine Alternative?Scrollen Sie nach unten in UITableView

- (void)viewWillAppear:(BOOL)animated { 

    [super viewWillAppear:animated]; 

    dispatch_async(dispatch_get_main_queue(), ^{ 

     NSIndexPath* lastIndexPath = [NSIndexPath indexPathForRow:_messagesArray.count-1 inSection:0]; 
     [_tableView scrollToRowAtIndexPath:lastIndexPath atScrollPosition:UITableViewScrollPositionTop animated:NO]; 
    }); 
} 
+0

Verwendung setContentOffset statt –

Antwort

0

Verwenden UITableViewScrollPositionBottom statt UITableViewScrollPositionTop.

0
- (void)viewWillAppear:(BOOL)animated { 

    [super viewWillAppear:animated]; 

    dispatch_async(dispatch_get_main_queue(), ^{ 
     CGFloat height = _tableView.contentSize.height - _tableView.bounds.size.height; 
     [_tableView setContentOffset:CGPointMake(0, height) animated:YES]; 
    }); 
} 
0

ich denke, das ist, was Sie wollen:

extension UITableView { 

    func scrollToBottom() { 
     scrollToRow(at: IndexPath(row: numberOfRows(inSection: numberOfSections-1)-1, section: numberOfSections-1), 
        at: .bottom, animated: true) 
    } 
}