When using a custom cell in a UITableView I am getting a strange table overlap:
Problem
Based on Rajesh Balam's Answer here is working form of my original code from my UITableViewDataSource!
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
/**********************************************************/
/* @soln a UNIQUE 'cellId' is the key */
/**********************************************************/
let cellId :String = "Cell" + String(indexPath.row);
var cell : UITableViewCell? = tableView.dequeueReusableCellWithIdentifier(cellId);
if (cell == nil){
cell = UITableViewCell(style: .Default, reuseIdentifier:cellId); //comment this out and watch it fail!
}
let cellText:String = self.items[indexPath.row];
let subjectField:UILabel = UILabel(frame: CGRect(x:55, y: 25, width: 303, height: 25));
subjectField.text = cellText;
(cell! as UITableViewCell).addSubview(subjectField);
return cell! as UITableViewCell;
}
It works. THANK YOU Rajesh!!! :)