Ios 轻触选项卡栏时将tableview滚动到顶部
在选择选项卡栏项目时,我需要一直向上滚动表格视图。 我试过了,但没用Ios 轻触选项卡栏时将tableview滚动到顶部,ios,swift,uitableview,tableview,Ios,Swift,Uitableview,Tableview,在选择选项卡栏项目时,我需要一直向上滚动表格视图。 我试过了,但没用 func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) { let tabBarIndex = tabBarController.selectedIndex if tabBarIndex == 0 { let indexPath = NSI
func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
let tabBarIndex = tabBarController.selectedIndex
if tabBarIndex == 0 {
let indexPath = NSIndexPath(row: 0, section: 0)
MyViewController().tableView.scrollToRow(at: indexPath as IndexPath, at: .top, animated: true)
}
}
调用了该方法,但tableView没有滚动到顶部。问题是您正在创建一个新的MyViewController实例,而不是访问屏幕上的实例。您需要访问已创建的viewController,幸运的是,this delegate方法将其交给您 换行
MyViewController().tableView.scrollToRow(at: indexPath as IndexPath, at: .top, animated: true)
到
问题是您正在创建一个新的MyViewController实例,而不是访问屏幕上的实例。您需要访问已创建的viewController,幸运的是,this delegate方法将其交给您 换行
MyViewController().tableView.scrollToRow(at: indexPath as IndexPath, at: .top, animated: true)
到
self.tableviewObject.scrollToRowAtIndexPath(indexPath, atScrollPosition: .Top, animated: true)