我正在为iPhone写一个圣经记忆应用程序,我需要一些帮助来挑选UIWebView中显示的经文。
我有一个读入UIWebView的xml文件,我需要能够告诉用户何时点击特定的诗句。以下是xml文件的示例:
<bible translation="KJV">
<testament name="Old">
<book name="Genesis">
<chapter number="1">
<verse number="1">In the beginning God created the heaven and the earth.</verse>
<verse number="2">And the earth was without form, and void; and darkness was upon the face of the deep. And the Spirit of God moved upon the face of the waters.</verse>
<verse number="3">And God said, Let there be light: and there was light.</verse>
<verse number="4">And God saw the light, that it was good: and God divided the light from the darkness.</verse>
<verse number="5">And God called the light Day, and the darkness he called Night. And the evening and the morning were the first day.</verse>
关于上面的代码,如果用户点击“在开始......”,程序需要知道(至少)用户刚刚点击了“verse”元素及其“number = 1”。
=================== EDITED ======================== ==
这是我提出的解决方案......类型。 让我知道它听起来如何。
我仍然有UIWebView读取XML文件。它也被格式化为捆绑中的CSS文件。由于UIWebViews记录了链接(hrefs)[感谢Jonathan]我可以在每个标记的诗歌前添加诗句数字(我知道它有点乏味,但我还是打算这样做:)
这样,xml文件将如下所示:
<bible translation="KJV">
<testament name="Old">
<book name="Genesis">
<chapter number="1">
<n>1</n><verse number="1">In the beginning God created the heaven and the earth.</verse>
<n>2</n><verse number="2">And the earth was without form, and void; and darkness was upon the face of the deep. And the Spirit of God moved upon the face of the waters.</verse>
<n>3</n><verse number="3">And God said, Let there be light: and there was light.</verse>
<n>4</n><verse number="4">And God saw the light, that it was good: and God divided the light from the darkness.</verse>
<n>5</n><verse number="5">And God called the light Day, and the darkness he called Night. And the evening and the morning were the first day.</verse>
<n>6</n><verse number="6">And God said, Let there be a firmament in the midst of the waters, and let it divide the waters from the waters.</verse>
<n>7</n><verse number="7">And God made the firmament, and divided the waters which were under the firmament from the waters which were above the firmament: and it was so.</verse>
我要么使用css强制将'n'标记强制为链接,要么只使用'href'元素。 这样一来,当这节经文中将会出现的经文编号被挖掘出来时,我可以用一种自定义的方法来弄清楚我在哪里(我所说的是什么)。 这是我发现的关于拦截UIWebView中链接触发的帖子: http://dblog.com.au/iphone-development/iphone-sdk-tip-firing-custom-events-when-a-link-is-clicked-in-a-uiwebview/
我希望这会起作用,它有点广告......但程序通常都是这样开始的。 以前有人试过这样的事吗?
唐
答案 0 :(得分:0)
UIWebView委托仅响应链接(hrefs),因此这可能是个问题。从理论上讲,你可以通过做一些命中检测来解决这个问题,但是更可取的是(加上你晚上睡得更好:D)解析XML并将其加载到UITableView中,更加可维护和方便更多用户友好。