2012-01-25 24 views
0

私のアプリでは、TapDetectingWindowを使用してUIWebViewのタッチを検出しています(正確にはhttp://mithin.in/2009/08/26/detecting-taps-and-events-on-uiwebview-the-right-wayを参照)。 ヘッダファイルで参照して提案し、以下のように私はWebViewのTapDetectingWindowが正しく機能していません

- (id)init { 
    self = [super init]; 
    if (self) { 
      tapDetectingWindow = (TapDetectingWindow *)[[UIApplication sharedApplication].windows objectAtIndex:0];            //mWindow, variable reference to TapDetectingWindow 
     tapDetectingWindow.viewToObserve = webView; 
     tapDetectingWindow.controllerThatObserves = self;  

     webView = [[UIWebView alloc] init]; 
     [webView setFrame:CGRectMake(0, 0, 340, 1900)]; 
     [webView setTag:1]; 
     [webView addSubview:keyboardText]; 
     [webView setUserInteractionEnabled:NO]; 
     [webView setDelegate:self]; 
     [webView setOpaque:0.0]; 

     [webView loadHTMLString:htmlString baseURL:NULL]; 
     [self.view addSubview:webView]; 

     keyboardText = [[UITextField alloc] init]; 
     keyboardText.autocorrectionType = UITextAutocorrectionTypeNo; 
     [keyboardText setDelegate:self]; 
     [self.view addSubview:keyboardText]; 

    } 
    return self; 
} 

のような実装ファイルに1ビューコントローラでそれを使用しますが、私のアプリは
「tapDetectingWindow.viewToObserve =のWebView」でクラッシュし
とレポート*- [UIWindow setViewToObserve:]:認識されていないセレクタは、いずれかが私を助けることができるのインスタンスに0x4a26b90

を送った...

答えて

4

P問題は上記のコードにありません。 UIApplicationDelegateプロトコルの下で名前ウィンドウを持つiOS 5.0の新しいプロパティ導入によるものです。

あなたのウィンドウ名をappdelegateファイルに変更してください。これが役立つの.mファイルは.hファイルで

@class WebViewController; 
@class TapDetectingWindow; 
@interface test_touchAppDelegate : NSObject <UIApplicationDelegate> 
{ 
    TapDetectingWindow *myWindow; 
    WebViewController *viewController; 
} 
@property (retain, nonatomic) TapDetectingWindow *myWindow; 
@property (retain, nonatomic) WebViewController *viewController; 
@end 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.myWindow = [[TapDetectingWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    self.viewController = [[WebViewController alloc] init]; 
    self.myWindow.rootViewController = self.viewController; 
    [self.myWindow makeKeyAndVisible]; 
    return YES; 
} 

ホープ。

+0

私は上記のようにコードを変更し、同じ時点でクラッシュしています。ここでWebViewControllerは何ですか、iamは1つのView Controllerのみを使用し、WebViewをサブビューします。 – Valli

+0

Webビューでジェスチャーを認識する別の方法はありますか? – Valli

0

Apurvがあなたに言ったことは正しいと魅力のように動作します。私は、あなたがウェブビュー上でジェスチャーを認識するための別の方法を尋ねるのを見る(私はそれがUIWebViewをクリックすることを意味すると仮定する)。答えは「はい」です。「UIWebViewデリゲートメソッド」を使用する必要があります。

#pragma mark - 
#pragma mark uiwebview delegate 

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType 
{ 
    if(navigationType==UIWebViewNavigationTypeLinkClicked){ 
     NSURL *URL = [request URL]; 
     if(URL){ 
      [[UIApplication sharedApplication] openURL:URL]; 
      return NO; 
     } 
    } 
    return YES; 
} 

上記のコード、あなたがUIWebViewをクリックしたとき、それはあなたがクリックしたUIWebViewのリンクを開きます。がんばろう。

関連する問題