以编程方式切换 tabBarController viewContoller 时发出 ajax 请求

发布于 2024-11-02 02:52:30 字数 1118 浏览 0 评论 0原文

我已经阅读论坛帖子并敲了我的头超过两个小时了,希望有人能帮助我指出正确的方向。

我正在使用 UITabBarController 并有 4 个与之关联的根视图。 在第一个视图中,用户可以拍照(UIImagePicker),然后以编程方式显示第二个视图。显示第二个视图后,我想向服务器发出 ajax 请求。

我可以使用以下代码成功选择/显示第二个视图:

self.tabBarController.selectedIndex = 1;

但是,未调用 UITabBarControllerDelegate 方法(在用户 tabBarContoller touches 上成功调用该方法):,

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController

因为 Apple tabBarController:didSelectViewController 文档 指出:

在 3.0 版本之前的 iOS 版本中,仅当所选视图控制器实际发生更改时才会调用此方法。换句话说,当选择相同的视图控制器时,不会调用它。此外,还会调用该方法来对选定的视图控制器进行编程更改和用户启动的更改。

所以我的问题是:“如何在以编程方式切换到第二个视图后执行一些代码并发出请求?

我也尝试将跟踪放入:

-(void)viewDidAppear 
-(void)ViewWillAppear 
-(void)viewDidLoad

但当 tabBarController.selectedIndex 时,这些都不会被调用放。

非常感谢

I've been reading through forum posts and banging my head for over 2hrs now and hopefully someone can help point me in the right direction.

I am using the UITabBarController and have 4 root views associated to it.
In the first view, the user can take a picture (UIImagePicker), after which the second view is displayed programmatically. Once the second view is displayed I want to make an ajax request to a server.

I am able to sucessfully select/display the second view with the following code:

self.tabBarController.selectedIndex = 1;

However the UITabBarControllerDelegate method (which is successfully called upon user tabBarContoller touches):

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController

is not called, as Apple tabBarController:didSelectViewController documentation states:

In versions of iOS prior to version 3.0, this method is called only when the selected view controller actually changes. In other words, it is not called when the same view controller is selected. In addition, the method was called for both programmatic and user-initiated changes to the selected view controller.

So my question is: "How can I execute some code & make a request after programmatically switching to second view?"

I also tried putting traces in:

-(void)viewDidAppear 
-(void)ViewWillAppear 
-(void)viewDidLoad

but none of those are called when tabBarController.selectedIndex is set.

Many Thanks

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

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

发布评论

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

评论(1

兰花执着 2024-11-09 02:52:30

应该调用 viewWillAppear ..我刚刚测试了它。

另一个解决方案:使用 UITabBarControllerDelegate

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController

跟踪更改。

viewWillAppear should be called.. I just tested it.

Another solution: use the UITabBarControllerDelegate with

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController

for tracking changes.

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