I have UITableView
with dynamic cells. In viewDidLoad
I have NSURLSession
which download some data to common variable someDataArray: [NSString]
. I'm using AutoLayout and UILabel in my cell has constraints like this. When view is loaded I want see all cells are same size (for example: 100). But when cell is tapped I want to change height of this cell to height size of UIlabel
frame
So my code looks like:
class someVC: UIViewController, UITableViewDelegate
{
var someDataArray: [NSString] = []
var cellTapped = 0
override func viewDidLoad() {
//NSURLSession download to someDataArray[]
}
func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell!
{
let cell = self.table.cellForRowAtIndexPath(indexPath) as customCellVC
cell.someTextView.text = someDataArray[indexPath.row]
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let cell = self.table.cellForRowAtIndexPath(indexPath) as customCellVC
if(cellTapped == 0) {
cellTapped = 1
table.beginUpdates()
table.endUpdates()
} else {
cellTapped = 0
table.beginUpdates()
table.endUpdates()
}
}
func tableView(tableView: UITableView!, heightForRowAtIndexPath indexPath: NSIndexPath!) -> CGFloat
{
// heightForRowAtIndexPath call first, how to calculate the size of frame uilabel? When it's tapped or not
// how to make all UILabel one size by load but sizetofit by tap on it?
}
}