标签栏,每次按下标签时都会重新加载

发布于 2024-11-06 06:46:04 字数 50 浏览 4 评论 0原文

我正在创建一个应用程序,其中有五个选项卡。每次按下选项卡时我都需要重新加载每个控制器。

I am creating an app in which I have five tabs. I need to reload each controller every time when tab is pressed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

我不是你的备胎 2024-11-13 06:46:04

把你想要重新加载的代码,在视图中将出现或者在视图中确实出现过的所有视图中。

一切顺利。

Put the code you want to reload, in the view will appear or in view did appear of all the view.

All the best.

甜味拾荒者 2024-11-13 06:46:04

例子:

   // AppDelegate ( and <UITabBarControllerDelegate> )
   // Creation tabbar and controllers               
    UIViewController* myController1 = [[UIViewController alloc] init] autorelease];
    UINavigationController* nav1 = [[[UINavigationController alloc] initWithRootViewController:myController1] autorelease];

    UIViewController* myController2 = [[UIViewController alloc] init] autorelease];
    UINavigationController* nav2 = [[[UINavigationController alloc] initWithRootViewController:myController2] autorelease];

    NSArray *array = [NSArray arrayWithObjects: myController1, myController2, nil];

    UITabBarController* tab = [[[UITabBarController alloc] init] autorelease];
    tab.viewControllers = array;
    tab.delegate = self; // <-- don't forget set delegate for TabBarController


    // TabBarController Delegate methods   
    - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController;
    {
            // Reload selected VC's view
        [viewController.view setNeedsDisplay];
    }

Example:

   // AppDelegate ( and <UITabBarControllerDelegate> )
   // Creation tabbar and controllers               
    UIViewController* myController1 = [[UIViewController alloc] init] autorelease];
    UINavigationController* nav1 = [[[UINavigationController alloc] initWithRootViewController:myController1] autorelease];

    UIViewController* myController2 = [[UIViewController alloc] init] autorelease];
    UINavigationController* nav2 = [[[UINavigationController alloc] initWithRootViewController:myController2] autorelease];

    NSArray *array = [NSArray arrayWithObjects: myController1, myController2, nil];

    UITabBarController* tab = [[[UITabBarController alloc] init] autorelease];
    tab.viewControllers = array;
    tab.delegate = self; // <-- don't forget set delegate for TabBarController


    // TabBarController Delegate methods   
    - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController;
    {
            // Reload selected VC's view
        [viewController.view setNeedsDisplay];
    }
尽揽少女心 2024-11-13 06:46:04
 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    //other codes

    [self.tabBarController setDelegate:self]

    //other codes
    }

// UITabBarControllerDelegate method.
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    if ([viewController respondsToSelector:@selector(reloadDataTemp)]) {
        [(YourViewController *)viewController reloadData];
    }
}
 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    //other codes

    [self.tabBarController setDelegate:self]

    //other codes
    }

// UITabBarControllerDelegate method.
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    if ([viewController respondsToSelector:@selector(reloadDataTemp)]) {
        [(YourViewController *)viewController reloadData];
    }
}
时光与爱终年不遇 2024-11-13 06:46:04

因此,编写一个方法来重绘页面上的元素,并在按下 Tab 键时调用它。如果您提供有关您所面临问题的更多信息,我将编辑这篇文章。

So write a method to redraw the elements on your page and call it on tab press. I will edit this post if you provide more information on the problem you are facing.

月亮是我掰弯的 2024-11-13 06:46:04

如果你正在使用 uitableview 使用这个

[tableview reloaddata];

if you are you are using the uitableview use this

[tableview reloaddata];
累赘 2024-11-13 06:46:04

我希望您谈论的是 webview,每次导航选项卡栏项目时,webview 都应该重新加载,只需在选项卡栏委托中实现 [webview reload] 即可。

I hope you are talking about the webview the webview should reload every time a tabbar item is navigated well just implement [webview reload] in the tab bar delegate.

梦幻之岛 2024-11-13 06:46:04

斯威夫特5


func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
        let vc = self.viewControllers?[1] as? stepVC // ViewController That need to be loaded
        vc?.viewDidLoad()

    }

Swift 5


func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
        let vc = self.viewControllers?[1] as? stepVC // ViewController That need to be loaded
        vc?.viewDidLoad()

    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文