您将如何设计问题/答案视图(iPhone SDK)

发布于 2024-08-26 23:44:56 字数 483 浏览 10 评论 0原文

我是 iPhone 开发新手,我有一个关于如何为我的应用程序创建视图的问题。

该视图应显示问题(使用格式化/语法突出显示的文本)以及多个可能的答案。用户应该能够单击答案来验证它。

目前,我正在尝试使用嵌入 UIWebView 作为 contentView 的 UITableView。这使我可以轻松显示格式化文本。 问题是计算和调整单元格的高度是一件真正的痛苦。我必须预加载 webview,调用 sizeToFit,获取其高度,并相应地更新单元格。这个过程应该针对问题和答案来完成(因为它们也是 HTML 格式的文本)。

实在是太痛苦了,我打算换个方向。我认为只使用一个大的 UIWebView 并用 HTML 设计所有内容。但我查看了一些描述如何在 HTML 页面和 ObjectiveC 代码之间进行通信的文章。这似乎也涉及到一些可怕的伎俩……

所以……就是这样,我真的不知道我应该做什么。 我想你们中的一些人以前处理过这样的事情,并且会提供一些非常感谢的提示:)

I'm new to iPhone development, and I have a question on how to create a view for my application.

The view should display a problem (using formatted/syntax highlighted text), and multiple possible answers. The user should be able to click on an answer to validate it.

Currently, I am trying to use a UITableView embedding UIWebView as contentView. That allows me to display formatted text easily.
The problem is that it is a real pain to compute and adjust the height of the cells. I have to preload the webview, call sizeToFit, get its height, and update the cell accordingly. This process should be done for the problem and the answers (as they are HTML formatted text too).

It's such a pain that I am planning to switch to something else. I thought using only a big UIWebView and design everything in HTML. But I looked at some articles describing how to communicate between the HTML page and the ObjectiveC code. This seems to involve some awful tricks too...

So... that's it, I don't really know what I should do.
I guess some of you dealt with such things before, and would provide some greatly appreciated tips :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乜一 2024-09-02 23:44:56

这里的问题是 iPhone API 尚不支持 NSAttributedString,因此您不能仅将文本设置为在文本视图中按您希望的方式显示。

我看到一项工作基本上使用单独的 UILabels 来表示每个属性运行。 (现在找不到链接。)他们使用 NSString UIKit 扩展来计算视图上字符串的位置,然后使用它来定位标签。

另一种解决方法是将字符串及其属性绘制到 UIImage 中,然后仅显示图像。我认为这将是最简单的解决方案。

在任何一种情况下,您都必须基本上重新创建属性字符串的数据结构。

NSAttributedString 为我们做了很多工作。当它消失时,我们真的很想念它。

The catch here is that the iPhone API does not yet support NSAttributedString so you can't just set the text to appear as you would like in a textview.

I saw one work around which essentially used individual UILabels to represent each attribute run. (Can't find the link now.) They used NSString UIKit extensions to calculate the position of the strings on the view and then used that to position the labels.

Another work around would be to draw the strings with their attributes to a UIImage and then just display the image. That would be the easiest solution I think.

In either case your going to have to basically recreate the data structure of an attributed string.

NSAttributedString does a lot of work for us. We really miss it when it is gone.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文