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つのコードの変更を提案できますか??