3

さて、私が取り組んでいるプロジェクトには、Twitterフィードがあり、それをテーブルに入れて、ツイートの主要部分をUITextViewに入れました。UIWebViewのテキスト内のリンクを開くことができるようにしたいと思います。以下を使用して、なんとかオープンURL呼び出しを傍受することができました。

#import "MyApplication.h"
#import "haydnboardAppDelegate.h"

@implementation MyApplication
- (BOOL)openURL:(NSURL *)url
{
   return [self openURL:url forceOpenInSafari:NO];
}


-(BOOL)openURL: (NSURL *)url forceOpenInSafari:(BOOL)forceOpenInSafari
{

    if(forceOpenInSafari)
    {
        // We're overriding our app trying to open this URL, so we'll let UIApplication     federate this request back out
        //  through the normal channels. The return value states whether or not they were able to open the URL.
        return [super openURL:url];
    }

    //
    // Otherwise, we'll see if it is a request that we should let our app open.

    BOOL couldWeOpenUrl = NO;

    NSString* scheme = [url.scheme lowercaseString];
    if([scheme compare:@"http"] == NSOrderedSame
       || [scheme compare:@"https"] == NSOrderedSame)
    {
        // TODO - Here you might also want to check for other conditions where you do not want your app opening URLs (e.g.
        //  Facebook authentication requests, OAUTH requests, etc)

        // TODO - Update the cast below with the name of your AppDelegate
        // Let's call the method you wrote on your AppDelegate to actually open the BrowserViewController
        couldWeOpenUrl = [(haydnboardAppDelegate *)self.delegate openURL:url];
    }

    if(!couldWeOpenUrl)
    {
        return [super openURL:url];
    }
    else
    {
        return YES;
    }
}
@end

main.hファイルも次のように変更しました。

return UIApplicationMain(argc, argv, @"MyApplication", nil);

コードでopenurl関数を呼び出そうとしましたが、関数をまったく呼び出さず、TextViewのリンクをクリックしても何も実行されません。ビューを変更する関数を呼び出すにはどうすればよいですか?

編集:アプリデリゲートの関数を実行するように管理しましたが、ViewControllerをプッシュしようとしても何も起こりません。ウィンドウ階層にないエラーviewControllerが発生したため、viewControllerで関数を呼び出すように関数を変更することにしましたが、それでも何も起こりませんが、viewControllerでpushViewControllerが呼び出されてもエラーメッセージは表示されません。これは、navigationController = nilが原因であることがわかりました。これを修正するにはどうすればよいですか?

4

0 に答える 0