我的根视图有一个名为update的按钮,隐藏了一个名为cHome的类
当用户退出RootView并转到另一个View时,我调用cEdit并有一个名为cEdit的类。有没有办法让这个视图在我的rootview上设置更新按钮的隐藏状态?所以当它调用时
[self.navigationController popViewControllerAnimated:YES];
要返回到根视图,更新按钮会有新的隐藏状态吗?
要返回根视图,更新按钮会有新状态吗?
答案 0 :(得分:0)
在你的根视图控制器上,你可以做一些简单的事情:这样,当你稍后调用时返回到根视图控制器:[self.navigationController popViewControllerAnimated:YES];
按钮将不再被隐藏。
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
self.update.hidden = NO;
}
答案 1 :(得分:0)
有一种方法可以做你想做的事,你可以实现自己的代表。
例如:
您在.h中创建一个新的类文件,添加此代码
#import <UIKit/UIKit.h>
@protocol ClassNameDelegate <NSObject>
@optional
- (void) tellUpdateButtonToHide;
@end
@interface ClassNameViewController : UIViewController
@property (weak,nonatomic) id <ClassNameDelegate>delegate;
您创建自己的委托,如果您想要访问协议,则必须添加属性
在.m文件中我只是在另一个控制器(不是rootVc)中添加一个按钮来更新rootController
- (IBAction)tellUpdateButtonToHide:(id)sender {
[self.delegate tellUpdateButtonToHide];
}
#import "ClassNameViewController.h"
@interface RootVcViewController : UIViewController<ClassNameViewControllerDelegate>
并在rootVc .m文件中实现方法tellUpdateButtonToHide;
- (void)tellUpdateButtonToHide{
[self dismissViewControllerAnimated:YES completion:nil];
[self.updateButton setHidden:NO];
}
和你的prepareForSegue
if ([segue.identifier isEqualToString:@"da"] ) {
ClassNameViewController *vc =(ClassNameViewController *)segue.destinationViewController;
[vc setDelegate:self];
}
希望它对你有用