如何将星级评级添加到UITableView单元格? [英] How to add star rating to UITableView cell?

查看:93
本文介绍了如何将星级评级添加到UITableView单元格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在我的iPhone应用程序中显示一堆 UITableViewCell 。样品如下。我知道如何为UITableView单元启用附件视图和图像,但问题是我需要在屏幕上添加星级评级。它背后没有任何奇特的逻辑,只有少数图像可以启用或禁用。

I need to display a bunch of UITableViewCell in my iPhone application. Sample look below. I know how I can enable accessory view and image to UITableView cell but the problem is that I need to add a star rating as visible on the screen. There's no fancy logic behind it, it will just be few images that will be either enabled or disabled.

我可以创建自定义 NIB中的UITableViewCell 但我如何在 cellForRowAtIndexPath 方法中使用它。如果它只是一个自定义单元格,我只需为它提供一个插座并将其与属性挂钩并在那里使用它。但由于它会被多次使用,我想我需要克隆它或以某种方式复制。

I though that I could create a custom UITableViewCell in NIB but how would I use it in cellForRowAtIndexPath method. If it was just one custom cell I'd just provide an outlet for it and hook it with a property and use it there. But since it would be used multiple times I think I'll need to clone it or copy somehow.

将这些东西添加到UITableViewCell的最简单方法是什么?

What is the simpliest way of adding such stuff to UITableViewCell?

alt text http://stuff.rajchel.pl /iphonestars.png

推荐答案

在处理自定义TableView单元格时,这个Matt Gallagher帖子对我帮助很大 http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing .html

This Matt Gallagher post helped me a ton when dealing with custom TableView cells http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html.

摘要
1)不要将UITableViewCell子类化为
2)在cellForRowAtIndexPath方法中,将自定义子视图布局在顶部已经出局的UITableViewCell。

Summary 1) Do not subclass UITableViewCell 2) In the cellForRowAtIndexPath method, layout your custom subviews on top of the dequeued UITableViewCell.

要添加星号,只需使用UIButton,其中包含未突出显示的星的默认图像和突出显示的星的选定图像。

To add a star just use a UIButton with the default image of a unhighlighted star and a selected image of a highlighted star.

这篇关于如何将星级评级添加到UITableView单元格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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