これがViewController.mの私のコードです
#import "ViewController.h"
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self addMyButton];
}
-(void)addMyButton {
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
webView.tag=55;
NSURL *url = [NSURL URLWithString:@"http://www.google.com"];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
[self.view addSubview:webView];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
action:@selector(aMethod:)
forControlEvents:UIControlEventTouchDown];
[button setTitle:@"Close" forState:UIControlStateNormal];
button.frame = CGRectMake(80, 210, 160, 40);
[button addTarget:self action:@selector(close:) forControlEvents:UIControlEventTouchUpInside];
[webView addSubview:button];
}
- (IBAction)close:(id)sender {
// [[self.view viewWithTag:55] removeFromSuperview];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)dealloc {
[super dealloc];
}
@end
そして、ここにViewController.hがあります
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController {
}
- (IBAction)close:(id)sender;
@end
すべて非常に単純ですが、次のエラーが発生し続けます。
-[ViewController aMethod:]: インスタンス 0x7141780 に送信された認識されないセレクタ
非常に不可解です!