问题
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
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.
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 UIButton
s) at runtime? Or do I have to code it all without using a XIB?
回答1:
In short, Yes.
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:
Table of questions -> question cell -> table of answers -> answer cell
.
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.
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.
Hope that helps.
来源:https://stackoverflow.com/questions/6637140/iphone-uitableviewcell-with-checkbox