【发布时间】:2017-07-24 22:28:47
【问题描述】:
怎么做?
我尝试了所有关于堆栈溢出的方法,但没有任何效果。我想要一个可以像 Instagram 一样工作的解决方案。如果您向下滚动点击TabBarItem 以转到顶部。(如果代码很重要,我通常使用tableviewControllers 而不是查看控制器)
任何帮助将不胜感激
在 swift 2.2 中谢谢!
我尝试了什么:
//Using the UiTabBarDelegate
class BarsViewController: UITableViewController,UISearchResultsUpdating,UISearchBarDelegate,UISearchDisplayDelegate,UITabBarControllerDelegate,UITabBarDelegate{
func tabBar(tabBar: UITabBar, didSelectItem item: UITabBarItem) {
if(item.tag == 1) {
//your code for tab item 1
tableView.scrollToTop(true)
}
else if(item.tag == 2) {
//your code for tab item 2
}
else if(item.tag == 4) {
//your code for tab item 4
self.tabBarItem.badgeValue = nil
tableView.scrollToTop(true) }
}
}
extension UITableView {
func scrollToTop(animated: Bool) {
setContentOffset(CGPoint.zero, animated: animated)
}
}
【问题讨论】:
标签: ios swift uitableview uitabbarcontroller scrolltop