학습 언어를위한 양방향 책을 만들고 있습니다. 그것은 독서, 퀴즈 그리고 간단한 게임을 가지고 있습니다. 각 장의 내용은 HTML 파일입니다. 이 책은 사용자가 텍스트에있는 약 300 단어를 배울 수 있도록합니다. Earch 단어는 다음과 같은 링크로 묶여 있습니다. < a href = "word"> 단어 </a> 사용자가 링크를 터치하면 모달보기가 해당 단어에 대한 번역 및 정보와 함께 나타납니다.iOS HTML 링크를 사용하여 데이터 가져 오기
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
// currentWord is the word in the link
self.currentWord = [[request URL] lastPathComponent];
// okToCatchLinks is a BOOL that I use to avoid showing the modalview when the page
// is loaded for the first time.
if (okToCatchLinks){
NSLog(@"Ok to catch links!");
WordViewController *viewController = [[WordViewController alloc] initWithNibName:@"WordViewController" bundle:nil]
// I did my homework creating the delegate protocol to dismiss the modal view.
viewController.delegate = self;
// This is a label in the modalview showing the word in the HTML link.
viewController.labelTitle = self.currentWord;
// Create a Navigation controller to add the "DONE" dismiss button
UINavigationController *navController = [[UINavigationController alloc]
initWithRootViewController:viewController];
navController.modalPresentationStyle = UIModalPresentationFormSheet;
navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
// show the navigation controller modally
[self presentModalViewController:navController animated:YES];
// Clean up resources
[navController release];
[viewController release];
}
okToCatchLinks = YES;
return YES;
}
내가 문자열 변수에 선택한 단어를 얻을 것이다이 코드 :
이
내가 링크를 얻기 위해 사용하고 코드입니다. 그런 다음 CoreData를 사용하여 DB에서 해당 단어를 검색합니다. HTML은 UTF-8로 인코딩됩니다. 그 단어를 다른 언어로 검색 할 수 있어야합니다. 따라서 사용자가 단어 (日本語) 또는 (이력서)를 클릭하면 DB에서 찾을 수 있어야합니다. 데이터 저장소의 경우 CSV 파일을 .sqlite 파일로 변환했습니다.더 좋은 방법이 있는지 궁금합니다. 개인적으로 나는 < a href = ""> 링크를 얻는 것을 좋아하지 않지만 링크에서 현재 단어를 얻는 다른 방법을 찾지 못했습니다. 또한 DB에서 해당 단어의 검색을 수행하는 것은 깨끗하지 않습니다. 각 행에 대해 UID를 사용하지 않기 때문입니다. 나는 그 단어를 지닌 문자열과 DB의 대응하는 열의 단어를 비교한다.
더 효율적인 방법이 있습니까?
다시 시작 : 단어 목록이 있으면 HTML에서 해당 단어를 표시하여 사용자가 해당 단어에 대한 정보를 DB에서 검색하고 검색 할 수 있도록하십시오.
고마워요! 대의원에 관해서는 맞습니다. 사과 권장 사항을 따르려고했지만 실제로는 동일한 modalview 내에서보기를 닫는 것이 더 편리해 보입니다. :) –