希望您已经声明了属性并合成了 IBOutlet button
。
在 SecondViewController.h 中创建 FirstViewController 的对象和属性并合成它。
SecondViewController.h
@interface SecondViewController {
.
.
FirstViewController *firstView;
.
.
}
@property (nonatomic,strong) FirstViewController *firstView;
@end
第二视图控制器.m
@implementation SecondViewController
.
.
@synthesize firstView;
.
.
@end
现在,当您从 firstView 呈现模态视图时
第一视图控制器.m
-(IBAction)presentModalView {
SecondViewController *secondView = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
secondView.firstView = self;
[self presentModalViewController:secondView animated:YES];
}
现在在您关闭 SecondViewController 的 SecondViewController 中,只需添加此代码。
第二视图控制器.m
-(IBAction)dismissModalView {
[self.firstView.button setHidden:YES];
[self dismissModalViewControllerAnimated:YES];
}
编辑:
参考这个链接:
Objective-C 中@interface 中的@protocol 实现
EDIT-2:使用协议实现
SecondViewController.h
@protocol SecondViewControllerDelegate <NSObject>
@required
- (void)hideButton;
@end
@interface SecondViewController {
.
.
id <SecondViewControllerDelegate> delegate;
.
.
}
@property (retain) id delegate;
@end
第二视图控制器.m
@implementation SecondViewController
.
.
@synthesize delegate;
.
.
@end
现在,当您从 firstView 呈现模态视图时
第一视图控制器.h
#import <UIKit/UIKit.h>
@interface FirstViewController : UIViewController<SecondViewControllerDelegate>
{
.
.
.
.
}
.
.
@end
第一视图控制器.m
-(IBAction)presentModalView {
SecondViewController *secondView = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
secondView.delegate = self;
[self presentModalViewController:secondView animated:YES];
}
#pragma mark - SecondViewController Delegate
- (void)hideButton
{
[self.button setHidden:YES]; //Here button is UIButton you want to hide when second view is dismissed.
}
现在在您关闭 SecondViewController 的 SecondViewController 中,只需添加此代码。
第二视图控制器.m
-(IBAction)dismissModalView {
[delegate hideButton];
[self dismissModalViewControllerAnimated:YES];
}
如果您需要更多帮助,请告诉我。
希望这可以帮助。