I've created a custom UIViewController with storyboard and this is the class: .h file:
#import <UIKit/UIKit.h>
@interface PlayerViewController : UIViewController
@property (weak, nonatomic) IBOutlet UILabel *PlayerNumber;
@property (weak, nonatomic) IBOutlet UIImageView *PlayerImage;
@property (weak, nonatomic) IBOutlet UILabel *PlayerNameLabel;
-(void)setPlayerName:(NSString*)PlayerNameString;
@end
.m file:
#import "PlayerViewController.h"
@interface PlayerViewController ()
@end
@implementation PlayerViewController
@synthesize PlayerImage,PlayerNameLabel,PlayerNumber;
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
-(void)setPlayerName:(NSString *)PlayerNameString{
self.PlayerNameLabel.text=PlayerNameString;
}
@end
from main view I create 2 instance of PlayerViewController in order to display 2 custom views:
- (void)viewDidLoad {
[super viewDidLoad];
[self DrawPlayerWithTag:1];
[self DrawPlayerWithTag:2];
}
- (void)DrawPlayerWithTag:(int)PlayerTag{
PlayerViewController *myPlayerViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PlayerViewController"];
UIView *myPlayerView=myPlayerViewController.view;
myPlayerView.tag=PlayerTag;
myPlayerView.frame=CGRectMake(0, 0, 100, 100);
myPlayerView.center = CGPointMake(self.view.frame.size.width / 2,
self.view.frame.size.height / 2);
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doDoubleTap)];
doubleTap.numberOfTapsRequired = 2;
[myPlayerView addGestureRecognizer:doubleTap];
[self.view addSubview:myPlayerView];
[myPlayerViewController setPlayerName:@"NameA"];
}
It seems to work. But, if I want to change the PlayerName, how can refer to view1 rather then view2 after a double tap event, and use the method setPlayerName?
Thanks a lot for your answer!