プロパティを宣言して IBOutlet を合成したことを願っていbutton
ます。
SecondViewController.h とプロパティで FirstViewController のオブジェクトを作り合成します。
SecondViewController.h
@interface SecondViewController {
.
.
FirstViewController *firstView;
.
.
}
@property (nonatomic,strong) FirstViewController *firstView;
@end
SecondViewController.m
@implementation SecondViewController
.
.
@synthesize firstView;
.
.
@end
firstView からモーダル ビューを表示すると、
FirstViewController.m
-(IBAction)presentModalView {
SecondViewController *secondView = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
secondView.firstView = self;
[self presentModalViewController:secondView animated:YES];
}
SecondViewController を閉じる 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
SecondViewController.m
@implementation SecondViewController
.
.
@synthesize delegate;
.
.
@end
firstView からモーダル ビューを表示すると、
FirstViewController.h
#import <UIKit/UIKit.h>
@interface FirstViewController : UIViewController<SecondViewControllerDelegate>
{
.
.
.
.
}
.
.
@end
FirstViewController.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 で、このコードを追加するだけです。
SecondViewController.m
-(IBAction)dismissModalView {
[delegate hideButton];
[self dismissModalViewControllerAnimated:YES];
}
これについてさらにサポートが必要な場合はお知らせください。
お役に立てれば。