显示很多RichText:选择最佳选项 [英] Displaying Lots Of RichText : Choosing the best option

查看:119
本文介绍了显示很多RichText:选择最佳选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

显示批次 RichText的最佳方式是什么(HTML格式化)

What is the best way to display lots of RichText (HTML formatted)

目前我我正在开发一个论坛的应用程序。正如您所期望的那样,网站上的帖子有很多HTML格式,列表,图像粗体文字,彩色文字等......

At the moment I'm working on an app for a forum. As you'd expect the posts on the site have lots of HTML formatting, lists, images bold text, colored text, etc...

现在我可以想到几个选项(非理想选择,如果你想到评论中发布的任何其他选项,请购买):

Now there are several options I can think of (non of them ideal, please if you think of any other options post them in the comments):


  • 使用 NSAttributedString + HTML + <的自定义单元格每个帖子的href =https://github.com/Cocoanetics/NSAttributedString-Additions-for-HTML/blob/master/Classes/DTAttributedTextView.h =noreferrer> DTAttributedTextView ?

  • Custom Cells using NSAttributedString+HTML + DTAttributedTextView for each post?

问题:我在其他地方的应用程序中使用了NSAttributedString + HTML类别,它不太理想,创建NSAttributedString似乎相当昂贵(慢),即使在小金额。
对于10个以上的帖子,每个帖子可能是整篇文章的长度会很糟糕 +尽管DTAttributedTextView支持IMG html标签(大多数标签)它不支持远程加载图像,除非你指定它们在img标签中的宽度和高度。对于IMG标签可能是笑脸(10 * 10)或屏幕截图(640 * 960)的论坛,无法预测。
(自编写此NSAttributedString + HTML以来,现已重命名为 DTCoreText ,已添加对< img> 标签并大大改进!)

Problems: I used the NSAttributedString+HTML categories in the app elsewhere and it was less then ideal, creating an NSAttributedString seems to be quite expensive (slow) even in small amounts. For 10+ posts each of which may be the length of an entire article would be awful + although DTAttributedTextView supports the IMG html tag (an most tags) it doesn't support remote loading of images unless you specify their width and height in the img tag. And for a forum where an IMG tag could be a smiley (10*10) or a screenshot (640*960) there's no way to predict that. (Since writing this NSAttributedString+HTML, which is now renamed DTCoreText, has added full support for <img> tags and improved greatly!)

每个帖子中包含UIWebView的自定义单元格?

这个我考虑了很长一段时间,但在阅读这篇博客文章我意识到了一个会导致平滑滚动的问题。为网站提供本机应用程序的想法是更好然后使用简单的UIWebView查看网站移动主题。如果应用程序滞后且不稳定而滚动更糟不是更好(同时我需要显示隐藏webview的图像,就像他建议不起作用)。还需要在主线程上创建UIWebView,否则它们会中断。

This one I considered for quite a while, however when reading this blog post I realised a problem that would cause, Smooth scrolling. The idea of having a native application for a site is that it is better then using a simple UIWebView to view the sites mobile theme. If the app lags and is jerky while scrolling that is worse not better (also as I need to display images hiding the webview's like he suggests wouldn't work). Also UIWebView's need to be created on the main thread or they break.

返回UIWebView?
另外烦人的做一个可怜的作弊,(比如 iFans app )你只显示文本,然后如果他们点击它,UIWebView加载所有漂亮的图像等...,唯一的选择似乎是做我认为TapaTalk应用程序做的,并将整个线程视图作为UIWebView 。这不是坏,因为它可能会有相当不错的性能,并允许我添加用户控制的主题等。但我发现在网站 native中使用UIWebView的想法 app令人厌恶。

Back to the UIWebView? Annoyingly besides doing a pathetic cheat, (like in the iFans app) where you only display text and then if they click it a UIWebView loads with all the nice images etc..., the only option left seems to be to do what I think the TapaTalk app does and have the entire thread view as a UIWebView. This isn't too bad as it will probably have quite good performance and will allow me to possibly add user controlled themes etc.. but I find the idea of using a UIWebView in a websites native app repulsive.

有没有人有创建网络应用的经验,比如也许一个Facebook客户端,论坛应用程序或新网站应用程序,它们必须显示来自网站的内容(我并不真正算一个Twitter客户端,因为它只需处理每个帖子少量的文本和链接)。或者有关在iOS应用中显示RichText内容的最佳方式的任何想法?

Does anyone have any experience creating web powered app, like maybe a facebook client, forum app, or new site app which had to display content from the site (I don't really count a twitter client as it only has to deal with text & links in small amounts per post). Or any ideas on the best way to display RichText content in an iOS app?

任何想法都必须处理该批次:

Any idea's would have to deal with the lot:


  • 多彩色文字。

  • 右,左和右中心对齐的文字。

  • 图像(可变大小)。

  • 粗体文字。

  • 不同的文字尺寸和尺寸字体。

  • 下划线文字。

  • YouTube视频。

  • HTML表格。

  • Multi Coloured Text.
  • Right, Left & Center aligned text.
  • Images (of variable size).
  • Bold text.
  • Text of different sizes & fonts.
  • Underlines text.
  • YouTube Videos.
  • HTML tables.

以防万一实际问题不是很清楚,我会总结一下:

为论坛客户端应用显示大量RichText(HTML格式)内容的最佳方式

推荐答案

因此,如果我正确阅读,您希望给定主题的论坛帖子是UITableView的单元格,并且单元格需要丰富的格式?

So if I am reading this right, you want the forum posts of a given topic to be cells of a UITableView and the cells need rich formatting?

假设这是正确的,我想每个帖子将占用很多屏幕(大单元格高度)。在这种情况下,将UIWebView作为子视图可​​能并不像您想象的那样糟糕。 UITableView重用单元格,所以实际上只需要将可见单元格加载到内存中。

Assuming this is correct, I imagine each post will take up a lot of the screen (large cell height). In this case, having a UIWebView as a subview might not be as bad performance-wise as you might think. UITableView reuses cells so really only the visible cells need be loaded into memory.

我还假设您可以通过API访问论坛,对吧?在这种情况下,您应该能够在加载视图之前立即预加载数据,而UIWebViews仅用于格式化。当您将HTMLString加载到UIWebView中时,您甚至可以从应用程序包中加载CSS文件,这样您就不会每次都从服务器加载它。

I'm also assuming you are able to access the forum via an API, right? In which case, you should be able to pre-load data immediately prior to loading the view and the UIWebViews will only be used for formatting. You can even load a CSS file from your app bundle when you loadHTMLString into your UIWebView so you're not loading that from a server every time.

所有这些,如果你确实有很多同时可见的单元格,那么它可能是一个不同的故事,我可能只考虑在UITableView索引中显示纯文本,并且仅当用户点击单元格以查看单个帖子时才显示丰富的格式。从设计角度来看,这也可能更好,因为屏幕上有大量不同格式的单元格可能最终看起来有点草率。

All that being said, if you did have a lot of concurrently visible cells it might be a different story and I'd maybe consider only showing plain text in the UITableView index and displaying the rich formatting only when the user taps the cell to view the single post. This might also be better from a design standpoint as having a ton of differently formatted cells on screen could potentially end up looking a bit sloppy.

此外,这可能是显而易见的(特别是因为你似乎兼顾了性能和设计)但请不要使用UIWebView进行UI控件。每当我看到UIWebView标签栏或假导航栏时,我都会畏缩(ack,Netflix)。但是,对于格式化,如果你从服务器加载大量动态内容,很多时候它是唯一的飞行方式。

Also, this may be obvious (especially since you seem to be both performance and design conscious) but please don't use UIWebView for UI controls. Any time I see a UIWebView tab bar or fake navigation bar I cringe (ack, Netflix). For formatting though, a lot times it's the only way to fly if you're loading a lot of dynamic content from a server.

这篇关于显示很多RichText:选择最佳选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆