У меня есть 3 класса.ViewController, WorkspaceView, MainMenuView.Как выполнить -(void)showMenu
из -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
, помещенного в WorkspaceView.m
(при щелчке по объекту workspaceView
, инициализированному в ViewController.m
)?mainMenuView
и workspaceView
созданы в ViewController
классе.
Надеюсь, вы понимаете;)
спасибо за помощь.
ViewController.h
#import <UIKit/UIKit.h>
#import "WorkspaceView.h"
#import "MainMenuView.h"
@interface ViewController : UIViewController
{
WorkspaceView *workspaceView;
MainMenuView *mainMenuView;
}
@property (nonatomic, retain) WorkspaceView *workspaceView;
@property (nonatomic, retain) MainMenuView *mainMenuView;
@end
ViewController.m
#import "ViewController.h"
@implementation ViewController
@synthesize workspaceView;
@synthesize mainMenuView;
#pragma mark - View lifecycle
- (void)viewDidLoad
{
// WorkspaceView
workspaceView = [[WorkspaceView alloc] initWithFrame:CGRectZero];
[self.view addSubview:workspaceView];
// ---
// MainMenuView
mainMenuView = [[MainMenuView alloc] initWithFrame:CGRectZero];
[self.view addSubview:mainMenuView];
// ---
...
}
...
@end
WorkspaceView.h
#import <UIKit/UIKit.h>
@interface WorkspaceView : UIView
@end
WorkspaceView.m
#import "WorkspaceView.h"
@implementation WorkspaceView
...
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:self];
//howto execute showMenu or hideMenu from MainMenuView using mainMenuView object in ViewController?
NSLog(@"workspace"); // <-it's work;
}
@end
MainMenuView.h
@interface MainMenuView : UIView
...
-(void)hideMenu;
-(void)showMenu;
@end
MainMenuView.m
#import "MainMenuView.h"
@implementation MainMenuView
- (id)initWithFrame:(CGRect)frame{
...
}
-(void)hideMenu{
self.frame = CGRectMake(0, -1 * self.frame.size.height, self.frame.size.width, self.frame.size.height);
}
-(void)showMenu{
self.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
}
@end