在IB中使用UITableViewCell的子类 - 为什么需要重写drawRect:?

发布于 2025-01-04 15:43:43 字数 613 浏览 4 评论 0原文

https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/TableView_iPhone/TableViewCells/TableViewCells.html#//apple_ref/doc/uid/TP40007451-CH7-SW12

关于子类化 UITableViewCell,上面的链接讨论了需要重写 drawRect: 来显式绘制单元格内容。

但为什么这是必要的呢?我们能不能只在IB中创建UITableViewCell的子类,在IB中添加所需的子视图,创建所需的插座连接,然后以编程方式设置这些子视图的值。

为什么需要重写drawRect:

https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/TableView_iPhone/TableViewCells/TableViewCells.html#//apple_ref/doc/uid/TP40007451-CH7-SW12

In relation to subclassing UITableViewCell, the above link talks about the need to override drawRect: to explicitly draw the cells content.

But why is this necessary? Can we not just create a subclass of UITableViewCell in IB, add the required subviews in IB, create the required outlet connections and then set the values of these subviews programmatically.

Why is there a need to override drawRect:?

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

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

发布评论

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

评论(2

独自←快乐 2025-01-11 15:43:43

您不需要重写drawRect:,就像您不需要使用UIAlertView 的textField 实现方法一样。然而,在某些情况下,绘制单元格的内容可以提高性能,特别是如果您有多个非不透明图层并且可以将它们绘制到一个不透明单元格中,因为渲染器不必多次合成和混合。通过绘制到单个不透明层中,硬件只需在其显示在屏幕上之前进行混合即可。

请注意,如果您没有遇到延迟或者每个单元格本身都有动画,那么绘图将不会对您有帮助。

You're not required to override drawRect: any more than you are required to use the textField implementation methods for UIAlertView. Drawing the cell's content, however, can boost performance in some cases, particularly if you have multiple non-opaque layers and can draw them into one opaque cell, because the renderer doesn't have to composite and blend multiple times. By drawing into a single opaque layer, the hardware only has to blend right before it gets displayed on screen.

Note that if you don't experience lag or if you have animation in each cell themselves, then drawing will not help you.

浅唱ヾ落雨殇 2025-01-11 15:43:43

我在你的链接中找不到它说你应该子类化 DrawRect 方法。
我不认为苹果推荐它。

我开发了一个完整的应用程序,其中包含许多带有自定义 tableViewCells 的 tableController,使用 nib 文件,并且从不子类化 drawRect 方法。

我从未注意到任何问题,并且我的应用程序成功通过了应用程序商店审核。

I can't find in your link where it says you are supposed to subclass DrawRect method.
I don't think apple recommand it.

I have developped an entire app with a lot of tableControllers with custom tableViewCells, using nib files and never subclassing drawRect method.

I never noticed any problem, and my app passed successfully the app store review.

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