iOS tabbed application with table view, how to reset table view tab? Beginner.

戏子无情 提交于 2019-12-12 03:22:56

问题


I have a tabbed application with 3 tabs

The first tab is a table view The second and third tabs are single page views

When a user clicks on a table cell in view one a new view is pushed on with a back button to the table cell.

Now lets say they click tab 2, then back to tab 1. The new view that was pushed on tab 1 is still visible. What I would like is to have the table view "reset" when they navigate away from it with another tab so that when they return they are presented with the table view instead of the new view that was pushed on .


回答1:


I agree with ElJay comment, but to answer the question use UITabBarControllerDelegate

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController

when a new tab is selected see if the current one is tab 1 selectedIndex property of tabBarController and if so popToRootViewController:




回答2:


As the others have said, this is probably not a good user experience. The idea of a tab controller is that it lets the user switch freely between the different parts of their app and go right back to what they were doing before.

If you're determined to do it this way, then make your navigation view controller's root view controller a custom subclass, and set it up as the tab bar controller's delegate.

In your custom view controller, implement the function shouldSelect(), as below:

func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool
{
  if viewController == self.navigationController {
    self.navigationController.popToRootViewController()
  }
  return true
}

Disclosure: I haven't tried to compile the code above, much less test it.



来源:https://stackoverflow.com/questions/8840978/ios-tabbed-application-with-table-view-how-to-reset-table-view-tab-beginner

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!