iOS使用HTML链接获取数据

iOS使用HTML链接获取数据,ios,cocoa-touch,core-data,uiwebview,Ios,Cocoa Touch,Core Data,Uiwebview,我正在写一本学习语言的互动书。它有阅读、测验和一些简单的游戏。每章的内容都是一个HTML文件。这本书允许用户学习文本中大约300个单词。Earch word包含在如下链接中:word当用户触摸该链接时,会出现一个模式视图,其中包含该单词的翻译和信息 这是我用来获取链接的代码: - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebVi

我正在写一本学习语言的互动书。它有阅读、测验和一些简单的游戏。每章的内容都是一个HTML文件。这本书允许用户学习文本中大约300个单词。Earch word包含在如下链接中:word当用户触摸该链接时,会出现一个模式视图,其中包含该单词的翻译和信息

这是我用来获取链接的代码:

- (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在数据库中搜索这个词。 HTML是UTF-8编码的。我必须能够用不同的语言搜索这个词。所以如果用户点击这个词(日本語) 或者(简历)我必须能够在数据库中找到它。 对于数据存储,我将CSV文件转换为.sqlite文件

我想知道是否有更好的方法来做到这一点。就我个人而言,我不喜欢使用获取链接,但我找不到任何其他方法来获取链接中的当前单词。在DB中执行该单词的搜索也不干净,因为我没有为每行使用任何UID。我只是将包含该单词的字符串与DB对应列中的单词进行比较

有没有更有效的方法

要继续:拥有单词列表,请在HTML中标记这些单词,以便用户可以从数据库中触摸并检索有关该单词的信息。

一些观察:

UID:只要您的单词是唯一的,您就可以使用该列作为主键,而无需使用单独的UID。实际上,核心数据将为您创建一个UID,因此您可以使用
objectWithID
检索单词

HTML链接:您使用
UIWebView
、HTML文件和链接的解决方案对我来说似乎是可行的。但是,您当然也可以使用
UITextView
,并使用
NSRange
以编程方式处理选择。这可能会更复杂,但也更“本机”

委托:如果要将信息传递回首先显示模型视图控制器的视图,则仅需要委托(作业太多!;-)。只是从内部将其排除在外

[self dismissModalViewControllerAnimated:YES];

谢谢关于代表,你是对的。我试图遵循苹果的建议,但事实上,从同一个modalview中排除这种观点似乎更方便:)