以编程方式从模态视图控制器切换父选项卡 [英] Programmatically switch parent tabs from modal view controller

查看:60
本文介绍了以编程方式从模态视图控制器切换父选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用中,您可以使用模式视图添加照片.当模式视图消失时,我想自动将标签栏控制器切换到第二个标签(照片查看器屏幕).

In my app, you can add a photo using a modal view. When the modal view gets dismissed, I want to automatically switch the tab bar controller to the second tab (the photo viewer screen).

我找到了此答案,了解如何以编程方式切换标签,但我不确定将该代码放在模态视图控制器中的什么位置.

I found this answer about how to programmatically switch tabs, but I'm not sure where to put this code in the modal view controller.

推荐答案

您可以创建委托协议,并为要模态显示的viewController分配一个委托属性,并使其在要调用dismissModalViewControllerAnimated时通知其委托.图片.

You can create a delegate protocol and assign a delegate property to the viewController being presented modally, and make it inform its delegate when it's about to call dismissModalViewControllerAnimated after taking a picture.

添加了有关实施的更多信息

edit: added some more information about implementation

在要模态显示的视图控制器类上,您将声明一个协议:

On the view controller class you are presenting modally, you would declare a protocol:

@protocol YourUIViewControllerSubclassDelegate;

然后,您需要在课程中添加一个属性:

Then, you would add a property to your class:

@property (nonatomic, unsafe_unretained)id <YourUIViewControllerSubclassDelegate>delegate;

最后,在类接口声明上调用@end之后,您将完成协议:

finally, after your call the @end on your class interface declaration, you would complete the protocol:

@protocol YourUIViewControllerSubclassDelegate <NSObject>
- (void)viewController:(YourViewControllerSubclass *)viewController isBeingDismissedWithImage:(BOOL)imageTaken;
@end

因此,在您的YourUIViewControllerSubclass中,在调用dismissModalViewControllerAnimated之前,您应该这样做:

So, inside your YourUIViewControllerSubclass, before calling dismissModalViewControllerAnimated, you would do:

[self.delegate viewController:self isBeingDismissedWithImage:YES or NO]; 

因此,当您创建YourUIViewControllerSubclass时,需要分配委托属性.谁是YourUIViewControllerSubclass的委托人,都需要遵守YourUIViewControllerSubclassDelegate协议,并实现协议方法.在协议方法的此实现内部,您将切换到想要切换到的任何选项卡.

So, when you create YourUIViewControllerSubclass, you need to assign the delegate property. Whoever is the delegate of YourUIViewControllerSubclass needs to conform to the YourUIViewControllerSubclassDelegate protocol, and implement the protocol method. Inside this implementation of the protocol method, you would switch to whatever tab you would like to switch to.

这篇关于以编程方式从模态视图控制器切换父选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆