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?
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.
Related
I need to show results of quiz which contains question text label and dynamic number of answers (Label + UIImage).
Which way of doing it is the best? Adding a tableview inside tableview? Or anything else?
You can just add a dynamic UITableView with a prototype section and a cell in a UIViewController each section has the question title in it and inside each section cell put a UIimageView & UILabelfor the different answers.
Don't forget your delegates and datasources plus create a UITableViewCell swift file to add the IBOutlets of the UIImageView & the UILabel. If you need a sample code i can provide you with one if you didn't really understood what i mean. But if you played with tabelViews before you will be able to do it easily.
In my app I have a TableView that displays a list of Items. Tapping on any cell will expand it and will display information related to tapped item. I want to display the information in tabular form, will it be a good approach to have a UITableView inside a UITableViewCell?
Have a look to my answer in this post.
I think it is what you are looking for.
I am suggesting u to go for master-detail view controllers :) ,for your question "have a UITableView inside a UITableViewCell " for this u need to subclass the UITableviewCell and in that cell u put or add another tableview by managing datasource and delegate in custom cell see my answer it shows how to add tableview within the custom UITableView cell see hear and before that u hav to incerease the row height for each cell i did not included it, "one thing i created all programatically not used xib" :) hope u get some idea .
This question already has answers here:
How to display multiple columns in a UITableView?
(6 answers)
Closed 10 years ago.
I'm creating an iOS app and will to create Table view cell with 3 columns inside of it. For example instagram profile page that contains the user information. Can this be achieved within xcode? I'm using a storyboard.
Yes it is very much possible in XCode. You'll have to create a custom UITableViewCell to create this. In your custom UITableViewCell you'll have to create different components as per your need.
I believe the yellow box in above pic is what you want to achieve. For this :
You'll have to create one custom cell with 3 UIImageView
EDIT :
In your UITableViewCell you'll have to create one UIImageView to show the profile picture.
Two UILabel one for the statistic. And, one for text.
One UIButton for Following.
How About the UICollectionView instead UITableView.
Create a custom cell.
You can either create the cell in interface builder or subclass UITableViewCell and overwrite its initWithStyle and layoutSubviews classes. You can access their properties within cellForRowAtIndexPath as usual. You could even do the layout in cellForRowAtIndexPath but I would not recommend that simply because of its bad style. For the user there would not be any difference.
I am interested to know how to add more than one piece of data into one line of data into a cell of UITableView.
For example in the StopWatch of the Clock App in Iphone, they are able to have more than one piece of data.
Lap Time Total
1 00.01.5 00.01.5
Interested to know how to add three values into one cell at a time...
You'll need to create your own cell, which inherits from UITableViewCell.
Here's an example of how to create your custom UITableViewCell.
You would have to create a custom uitableviewcell for that checkout this tutorial or refer to Apple Documentation for more detail
You could either subclass UITableViewCell, or you could choose the "Custom" attribute on IB on the cell, and drag and drop labels, buttons, and whatever you want into the UITableViewCell. Set tags on each IBOutlet you create. Then you can do like this in tableView:cellForRowAtIndexPath
UILabel *yourLabel = (UILabel *)[cell viewWithTag:tag]; // Set your own tag and outlet.
From there you can customize it just how you want, without having to subclass it.
When that is said, the usual way is to subclass UITableViewCell. That way, you can have each cell store information, and add the IBOutlets as properties to the CustomTableViewCell as normal. Then you could add the information to the CustomTableViewCell, and let the cell take care of the rest.
I was working with the grouped table view , and i wanted different controls for every row i.e switch control for 1st,radio button for 2nd ,checkbox for 3rd and so on.. how can this be implemented programmatically that is without using interface builder
thanks in advance
CharlieMezak said is right, you need to create in UIControls directly in cellForRowAtIndexPath , and add as subviews to contentView of the cell
For reference see the link below
http://www.e-string.com/content/custom-uitableviewcells-interface-builder
the link specifies the code to create cells programmatically as well as using IB.
Table View Programming Guide for iOS
Read the programing guide, and remember to use different CellIdentifier for each type of cell.
This is a pretty vague question.
Obviously you need to provide the cells to the tableview in its cellForRowAtIndexPath delegate/datasource method. So, either in that method or during the initialization of your view controller, build the UITableViewCell instances that you need, adding the various controls that you want to them as subviews and connecting the controls to your view controller so you can detect when they have been changed. Then just return the appropriate cell in the cellForRowAtIndexPath method.
Personally, I think it's a lot easier to use IB in cases like this. Just create an IBOutlet instance variable for each custom cell you want, and return the right cell in cellForRowAtIndexPath.