iPhone UITableViewCell with checkbox

谁说我不能喝 提交于 2019-12-22 12:37:58

问题


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 UIButtons) 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!