带有复选框的iPhone UITableViewCell [英] iPhone UITableViewCell with checkbox

查看:84
本文介绍了带有复选框的iPhone UITableViewCell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义子类 UITableViewCell ,它将包含一些标签,我想在其中添加一些复选框功能。一个问题标签和五个选项可以多选择 UITableviewCell 子类

I have a custom-subclassed UITableViewCell which will include a few labels, to which I want to add some checkbox functionality. One question label and five options are multi-selectable in that UITableviewCell subclass

因为我已经在一个单元格中,是否可以使用 UITableViewCellAccessoryCheckmark 来模仿复选框功能?另一种选择是使用 UINavigationController 导航到另一个tableview,但我希望用户在同一页面中查看选项。

Since I'm already in a cell, is it possible to use UITableViewCellAccessoryCheckmark to imitate checkbox functionality? Another option would be to navigate to another tableview using UINavigationController, but I want the user to see the options in the same page.

另外,由于我事先不知道选项的数量,是否可以使用XIB设计这个自定义单元格,但仍然动态添加一些项目(例如 UISwitch ,或 UIButton s)在运行时?或者我是否必须在不使用XIB的情况下对其进行编码?

Also, since I don't know the number of options beforehand, is it possible to design this custom cell using a XIB and yet still dynamically add some items (for example UISwitch, or UIButtons) at runtime? Or do I have to code it all without using a XIB?

推荐答案

简而言之,是的。

UITableViewCell UIView 。也就是说你可以在其中插入一个 UITableView 并创建你的复选框allike单元格。将其视为嵌套表:

UITableViewCell is a subclass (somewhere down the way) of a UIView. That said you can insert a UITableView in it and create your checkbox allike cells. Think of it as nested tables:

问题表 - >问题单元格 - >答案表 - >回答单元格

所以你要做的就是自定义 UITableViewCell 实现 UITableViewDelegate UITableViewDataSource 然后你想在IB中插入一个UITableView。

So what you want to do is to make your custom UITableViewCell implement UITableViewDelegate and UITableViewDataSource then you want to insert an UITableView in the IB.

如果要显示带有4个答案的问题单元格,您可以将答案参数作为 NSArray 传递给自定义 UITableViewCell 。然后它将使用它来创建将作为答案单元行为的内部单元格。

When you want to show your question cell with 4 answers you would pass a parameter of answers as a NSArray to the custom UITableViewCell. It then will use it to create inner cells that will behave as answer cells.

希望有所帮助。

这篇关于带有复选框的iPhone UITableViewCell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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