XcodeでUIViewController(aViewController)、UIView(bView)のファイルを作り、
bViewをaViewControllerの上に乗せている状態にしています。
bViewで作ったボタンを押すと、aViewControllerの画面遷移をするメソッド"function"を実行するというようにしたいのですが、"unrecognizerd selector sent to instance..."エラーになってしまいます。
bView内にfunctionを書き、pushの画面遷移を行う方法も考えたのですが、こちらはボタンは押せますが何も反応しませんでした....
この場合どのように書けば良いのでしょうか?
よろしくお願いいたします。
aViewController.h
#import "bView.h" #import "cViewController.h" ... -(void)function;
aViewController.m
-(void)viewDidLoad{ bView = [[bView alloc]init]; [bView makeView]; bView.bViewController = self; [self.view addSubView:bView]; } -(void)function{ cViewController *nextViewController = [[cViewController alloc] initWithNibName: nil bundle: nil]; [self.navigationController pushViewController: nextViewController animated: YES]; }
bView.h
#import "bViewController.h" pinterface bView : UIView{ UIButton btn; bView *BView; } -(void)makeView; -(void)function; @property (nonatomic,readonly) UIButton *btn; @property (assign) UIViewController* aViewController;
bView.m
#import "bView.h" #import "aViewController.h" @impementation bView @synthesize btn; @synthesize aViewController; -(void)makeView{ btn= [UIButton buttonWithType:UIButtonTypeRoundedRect]; UIImage *btnimg = [UIImage imageNamed:@"btn.png"]; [btn setBackgroundImage:btnimg forState:UIControlStateNormal]; btn.frame = CGRectMake(65, 380, 60, 60); [self addSubview:btn]; btn.userInteractionEnabled = YES; [btn addTarget:aViewController action:@selector(function) forControlEvents:UIControlEventTouchUpInside]; }
回答1件
あなたの回答
tips
プレビュー