这是我的 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 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[ViewController aMethod:]:无法识别的选择器发送到实例 0x7141780”
很莫名其妙!