2012-11-08 151 views
0

林從按鈕hulp崩潰時,在一個UIWebView關閉PDF

這打開一個PDF的代碼是:

-(IBAction)hulp; 
{ 
NSString *path = [[NSBundle mainBundle] pathForResource:@"Handleiding" ofType:@"pdf"]; 
NSURL *targetURL = [NSURL fileURLWithPath:path]; 
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL]; 
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]; 
webView.tag=55; 
[[webView scrollView] setContentOffset:CGPointMake(0,500) animated:YES]; 
[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"window.scrollTo(0.0, 50.0)"]]; 
[webView loadRequest:request]; 
[self.view addSubview:webView]; 
[webView release]; 

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
[button addTarget:self 
      action:@selector(aMethod:) 
forControlEvents:UIControlEventTouchDown]; 
[button setTitle:@"Close" forState:UIControlStateNormal]; 
button.frame = CGRectMake(80, 425, 160, 40); 
[button addTarget:self action:@selector(close:) forControlEvents:UIControlEventTouchUpInside]; 
[webView addSubview:button]; 

} 


- (IBAction)close:(id)sender { 

[[self.view viewWithTag:55] removeFromSuperview]; 


} 

有誰看到什麼即時做錯了:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[LocationTestViewController aMethod:]: unrecognized selector sent to instance 0x8087c60' 
    *** First throw call stack: 
(0x1f26012 0x15e8e7e 0x1fb14bd 0x1f15bbc 0x1f1594e 0x15fc705 0x38c920 0x38c8b8 0x44d671 0x44dbcf 0x44c872 0x3bc16d 0x3bc552 0x39a3aa 0x38bcf8 0x22badf9 0x22baad0 0x1e9bbf5 0x1e9b962 0x1eccbb6 0x1ecbf44 0x1ecbe1b 0x22b97e3 0x22b9668 0x38965c 0x244d 0x2385) 
    libc++abi.dylib: terminate called throwing an exception 
(lldb) 
+1

您是如何在課堂上實現aMethod的?請發佈代碼。 –

+0

i onl在my.h文件中添加 - (IBAction)關閉:(id)發件人 –

回答

1

是什麼此說明適用於:

[button addTarget:self 
      action:@selector(aMethod:) 
forControlEvents:UIControlEventTouchDown]; 

刪除它。

+0

謝謝!我會在幾分鐘內接受 –