简体   繁体   English

在UITableView中以编程方式自定义单元格?

[英]Custom Cell in UITableView programmatically?

I have a UITableView which gets loaded with data from a MutableArray. 我有一个UITableView,它从MutableArray加载了数据。 The thing is, within this array I have many different attributes, therefore I would like to enter these attributes into a custom cell programmatically. 问题是,在此数组中,我具有许多不同的属性,因此我想以编程方式将这些属性输入到自定义单元格中。

Also I would like to include a Slider within the Cell so there will need to be some sort of addition there. 另外,我想在该单元格中包含一个Slider,因此在那里需要进行某种添加。

You say you've looked at tutorials, but have you checked out the " UITableView construction, drawing and management (revisited) " post on http://cocoawithlove.com - this pretty much covers the full custom UITableViewCell gamut, including loading a custom view from a NIB. 您说您已经看过教程,但是您是否已在http://cocoawithlove.com上签出了“ UITableView的构造,绘图和管理(已重新访问) ”一文-这几乎涵盖了完整的自定义UITableViewCell色域,包括加载自定义从NIB查看。

Irrespective, one potential approach is to create your own custom cell that expends the UITableViewCell and simply add a UISlider property which you'd then set up within the - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier method and add it as a sub view via [[self contentView] addSubview:yourUISlider]; 无论如何,一种潜在的方法是创建自己的自定义单元格,以消耗UITableViewCell并简单地添加一个UISlider属性,然后在- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier方法和通过[[self contentView] addSubview:yourUISlider];将其添加为子视图[[self contentView] addSubview:yourUISlider]; , etc.

However, I'd be tempted to have a good look at the http://cocoawithlove.com article, and download the provided project as this will show you the available options in full. 但是,我很想看看http://cocoawithlove.com上的文章,并下载提供的项目,因为这将向您显示所有可用的选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM