2011-12-13 36 views
0

好吧,我正在從我發現的UiWebView示例製作應用程序。我需要添加一個按鈕,但這個例子的工作方式類似phonegap,所以我想通了,我需要添加按鈕作爲子視圖到窗口,所以然後我得到我的按鈕,並設置它的按下,但是當我有按下它我的應用程序崩潰...任何人都可以幫忙嗎?這裏是我的代碼片段:iPhone編碼按鈕有什麼問題

- (void)webViewDidFinishLoad:(UIWebView *)webView{ 
    myLoadingLabel.hidden = YES; 
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; 
    [window addSubview:webView]; 
//my button 
    UIButton *playButton = [[UIButton buttonWithType:UIButtonTypeCustom] retain]; 
    playButton.frame = CGRectMake(122, 394, 76, 76); 
    [playButton setTitle:@"Play" forState:UIControlStateNormal]; 
    playButton.backgroundColor = [UIColor clearColor]; 
    [playButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal ]; 
    UIImage *buttonImageNormal = [UIImage imageNamed:@"mic.png"]; 
    UIImage *strechableButtonImageNormal = [buttonImageNormal stretchableImageWithLeftCapWidth:12 topCapHeight:0]; 
    [playButton setBackgroundImage:strechableButtonImageNormal forState:UIControlStateNormal]; 
    UIImage *buttonImagePressed = [UIImage imageNamed:@"mic.png"]; 
    UIImage *strechableButtonImagePressed = [buttonImagePressed stretchableImageWithLeftCapWidth:12 topCapHeight:0]; 
    [playButton setBackgroundImage:strechableButtonImagePressed forState:UIControlStateHighlighted]; 
    [playButton addTarget:self action:@selector(playAction:) forControlEvents:UIControlEventTouchUpInside]; 
    [window addSubview:playButton]; 
} 

-(void)playAction { 
    NSLog(@"Button Pressed!"); 
} 

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIWebView_ExampleAppDelegate playAction:]:

哦,我知道了一個長鏡頭,但我需要的網頁之外的這個按鈕,因爲它需要的時候再次點擊時點擊,然後開始錄製音頻它需要停止錄製和保存,使用system()運行一個命令;然後把從系統命令獲得的數據放入uiwebview中以便使用...所以如果有人知道一些代碼我會很感激,並且它的越獄應用程序,所以系統命令將會好的。謝謝!!!

+3

什麼是崩潰? –

+0

@KevinBallard @KevinBallard這是我的錯誤,'***終止應用程序由於未捕獲的異常'NSInvalidArgumentException',原因:' - [UIWebView_ExampleAppDelegate playAction:]:' –

回答

2

您正在調用名爲playAction:的方法,但實現了一個名爲playAction的方法。介意失蹤的結腸。最有可能的崩潰與這個問題有關。

快速修復,改變

[playButton addTarget:self action:@selector(playAction:) forControlEvents:UIControlEventTouchUpInside]; 

[playButton addTarget:self action:@selector(playAction) forControlEvents:UIControlEventTouchUpInside]; 
+0

這兩個字符串是完全一樣的 –

+0

再次看 - 你錯過了collon – Till

+0

棘手:)感謝很多im快樂 –

1

問題是這樣的:

@selector(playAction:) 

- (void)playAction 

前者是指一種名爲-playAction:的方法,它接受一個參數,但您已實施一種名爲-playAction的方法,該方法不帶任何參數。從@selector塊中刪除冒號,它應該可以工作。

+0

不錯,但我很好 –