填空模型
我一直在试图找出我的这个新应用程序的正确模型。事情是这样的。我需要创建一个考试类型的应用程序。该应用程序将有一个“语法”部分,需要一个带有填空方法的段落。所以它会看起来像这样。
"Lorem ipsum dolor sit amet, _________________ , sed do eiusmod tempor
_______ ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud
exercitation ullamco _________________ ex ea commodo consequat. Duis aute
irure dolor in reprehenderit in voluptate velit esse _______ dolore eu fugiat nulla
pariatur. ____________ sint occaecat cupidatat non proident, sunt in culpa qui
officia deserunt mollit anim id est laborum."
现在,该段落来自服务器。我们将空格标记为 {#},因此当我在应用程序上显示它时,我会将其替换为“____”w/c相当于一个uitextfield。问题是我不知道该怎么做。我可以将所有内容放入 uitextview 中吗?我该如何处理空白?我不认为我可以用 uiwebview 做到这一点,因为我需要在点击空白后更新它们的内容。请帮忙。
I've been trying to figure out the correct model for this new app of mine. Here's the thing. I need to create an exam type app. The app will have a "Grammar" section which requires a paragraph with fill in the blanks approach. So it will look like this.
"Lorem ipsum dolor sit amet, _________________ , sed do eiusmod tempor
_______ ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud
exercitation ullamco _________________ ex ea commodo consequat. Duis aute
irure dolor in reprehenderit in voluptate velit esse _______ dolore eu fugiat nulla
pariatur. ____________ sint occaecat cupidatat non proident, sunt in culpa qui
officia deserunt mollit anim id est laborum."
Now, the paragraph is coming from the server. We mark the blanks as {#} so when I display it on the app I will replace it with "____" w/c is equivalent to a uitextfield. The problem is I've no idea how to go about this. Can I put everything in a uitextview? how should I deal with the blanks? And I dont think I can do this with uiwebview coz I need the update the contents of the blanks once I tap on them. Please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我的要求也是一样的,但我用本机代码解决了它,使用 UILabel & UIView,所有这些都是在一个循环中实际完成的。考虑下面的文字。
从前有一个人,名叫达摩克利斯。他的一个朋友最终 _____ 成为一座小城市的统治者。达摩克利斯想,‘我的朋友多么幸运____。他现在是一位统治者。他一定____ 度过了一段美好的时光。
其中每件作品都被视为
UILabel
,空白被视为UIView
。正确的选项位于有序列表中,如下所示。查看代码。
此方法为空白空间及其选项渲染整个 UI。
这些方法将准备 UILabel 输出 NSString。
此方法将有助于拖放和拖拽。放置功能
此方法将告诉您拖动的选项空白是正确还是错误
请随意使用代码 &我们非常欢迎改进 :)
继续编码!
My requirement was also same, but I solved it in native code, with UILabel & UIView, all of it done through pragmatically within a loop. Consider the below text.
Once upon a time there _____ a man called Damocles. A friend of his eventually _____ the ruler of a small city. Damocles thought, ‘How lucky my friend ____. He ____ now a ruler. He must ____ a great time.
In which each work is treated as
UILabel
empty spaces treated asUIView
. The correct options are in ordered list as show below.Check out code.
This methods renders entire UI for empty spaces and its options
These methods will prepare UILabel out NSString
This Method will help in drag & drop functionality
This Method will tell you dragged option empty space is correct or wrong
Please feel free to use code & improvements are happily welcome :)
Keep coding!
您可以使用 UIWebView。为了更新空白的内容,您可以在 HTML 页面中编写 javascript,并将其与空白的 onselect 事件绑定。
您可以看看我的答案 iOS UIWebView Javascript - 插入数据- 接收回调?
了解有关与 webview 通信的更多信息。 (即从 Objective C 执行 javascript,反之亦然)
更新注释
是的,您可以从外部将字符串传递给 webview,
并在您的 HTML 文件中编写一个 JS 函数来获取并在空白中显示该字符串,
You can use UIWebView. And for updating the contents of the blanks you can write javascript inside the HTML pages and bind it with onselect event of the blanks.
You can have a look at my answer iOS UIWebView Javascript - insert data -receive callbacks?
to know more about communicating with a webview. (i.e. executing javascript from Objective C and vice versa)
Update for the comment
Yes, you can pass a string to the webview from outside ,
and write a JS function is your HTML file to get and display the string in the blank,
我有时在 NSMutableStrings 中使用特殊标签作为替换字符串的占位符,然后根据需要用代码替换它们,例如...
如果您需要任何类型的良好格式,使用 UIWebView 将是最佳选择。
I sometimes use special tags in NSMutableStrings as placeholders for replacement strings, then replace them as needed with code like...
If you need any kind of nice formatting, using UIWebView would be the way to go.