0

Apple のアドレス帳を使用して単純な連絡先アプリを作成したビュー コントローラーがあります。ユーザーが生成ボタンをクリックすると、すべての連絡先と電話番号を作成して表示する Web ビューを持つ別のビュー コントローラーを作成しました。今私が必要としているのは、生成時に連絡先がハイパーリンクである必要があり、連絡先をクリックすると、最初のView Controllerで行った連絡先の詳細が表示されることです。私は webview の削除を使用する必要があることを知っていますが、それを実装する方法がわかりません。これまでのところ、これが私が書いたすべてです。

-(BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{

    ViewController *latestView = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    [self.navigationController pushViewController:latestView animated:YES]; 
    return YES;
}

これは、WebView で連絡先を生成して表示する機能です。この中で、連絡先の詳細とともにハイパーリンクを追加する方法を知りたいです。

- (IBAction)createFileAction:(id)sender {



    NSString *tweet, *phoneNumbers=@"", *temp, *allContacts=@"";
    addressBooks =ABAddressBookCreate();
    CFArrayRef people = ABAddressBookCopyArrayOfAllPeople(addressBooks);
    for (CFIndex i = 0; i < CFArrayGetCount(people); i++)
    {
        person12 = CFArrayGetValueAtIndex(people, i);
         tweet=[[NSString stringWithFormat:@"%@",(__bridge_transfer NSString *)ABRecordCopyValue(person12, kABPersonFirstNameProperty)] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];

        //Appending Last Name
        if(CFBridgingRelease(ABRecordCopyValue(person12,kABPersonLastNameProperty))!=NULL)
        {
            tweet=[tweet stringByAppendingString:@" "];
            tweet=[tweet stringByAppendingString:[[NSString stringWithFormat:@"%@",(__bridge_transfer NSString *)ABRecordCopyValue(person12, kABPersonLastNameProperty)] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]];
        }


        tweet=[@"<h5>" stringByAppendingString:[NSString stringWithFormat:@"%@",tweet]];
        if(CFBridgingRelease(ABRecordCopyValue(person12,kABPersonFirstNameProperty))!=NULL)
        {


            ABMultiValueRef multi = ABRecordCopyValue(person12, kABPersonPhoneProperty);
            if(ABMultiValueGetCount(multi)!=0)
            {
            //For fetching multiple Phone Numbers
            for (int i=0; i < ABMultiValueGetCount(multi); i++) 
                {
            temp = (__bridge NSString*)ABMultiValueCopyValueAtIndex(multi, i);
                phoneNumbers=[phoneNumbers stringByAppendingString:[NSString stringWithFormat:@"%@/",temp]];
                }



            //For Trimming characters in contacts (),-," "

            NSCharacterSet *trim = [NSCharacterSet characterSetWithCharactersInString:@"()-\" \""];
            phoneNumbers = [[phoneNumbers componentsSeparatedByCharactersInSet: trim] componentsJoinedByString: @""];
            phoneNumbers=[phoneNumbers substringToIndex:[phoneNumbers length]- 1];
            if([phoneNumbers rangeOfString:@"/"].location!=NSNotFound)
            {
                phoneNumbers = [phoneNumbers stringByReplacingOccurrencesOfString:@"/" withString:@" / "];
            }
            }
            else
            {
                phoneNumbers=[phoneNumbers stringByAppendingString:@"No Numbers"];

            }

            tweet=[tweet stringByAppendingString:@" ---> "];
            tweet=[tweet stringByAppendingString:[[NSString stringWithFormat:@"%@",phoneNumbers] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]];
            phoneNumbers=@"";

            NSLog(@"%@",tweet); 

        allContacts = [allContacts stringByAppendingFormat:@"%@</h5>",tweet];
        }

    }
    CFBridgingRelease(people);


        // To create file
        [self.fileMgr createFileAtPath:file contents:nil attributes:nil];

        [allContacts writeToFile:self.file atomically:NO encoding:NSStringEncodingConversionAllowLossy error:nil];


        //Test if file exists now that we have tried creating it
        if([self.fileMgr fileExistsAtPath:self.file])
        {

            NSString *content = @"Contact list generated click on view to show the list";
            [webview loadHTMLString:content baseURL:nil];
        }
        else 
        {

            NSString *content = @"Contact list is not created yet, click on create to generate the contact list";
            [webview loadHTMLString:content baseURL:nil];
        }



}

結果を達成するのに役立つこれら2つのコードの変更を提案できますか??

4

1 に答える 1

1

私があなたを正しく理解していれば、ViewController のインスタンスを開く HTML リンクが必要です。<a href="myapp://{some_id_of_the_person}">click here</a>個人のIDをViewControllerに渡したいと仮定すると、基本的に任意のタイプのリンクを作成できます。

次に、例のスキーム ( ) と一致する[UIWebView webView:shouldStartLoadWithRequest:navigationType:]かどうかを確認します。request.URL.schememyapp://

  • はいの場合は、その人の ID の URL を解析し、その人 (およびreturn NOメソッド) の viewController を開きます。
  • そうでない場合return YES(ビューに他の標準リンクがあり、通常は開く必要があると仮定します)。
于 2013-08-07T14:36:45.810 に答える