Remove specific subviews (swift)
<p>Question: How Can i just remove all the subview of UIButton? if i remove all subviews, it will remove the cell title as well.</p>

<p>This is my code:</p>

<pre><code>func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("idcell", forIndexPath: indexPath) as UITableViewCell
    let lblTitle : UILabel = cell.contentView.viewWithTag(101) as! UILabel
    lblTitle.text = (deptId[indexPath.row] as? String)! + "     " + (deptDesc[indexPath.row] as? String)!
    var height:CGFloat = 0
    cell.backgroundColor = UIColor.whiteColor()
    cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator

    if(indexPath == selectedIndexPath){
        cell.backgroundColor = UIColor.grayColor()
        for i in 0...deptProfile.count-1 {
            let deptmentProfile = UIButton(frame: CGRectMake(0,44+height,400,41))
            deptmentProfile.addTarget(self, action: "buttonAction:", forControlEvents: UIControlEvents.TouchUpInside)
            height = height+41
            deptmentProfile.setTitle(deptProfile[i] as! String, forState: UIControlState.Normal)
            deptmentProfile.setTitleColor(UIColor.blackColor(), forState: .Normal)
            deptmentProfile.contentHorizontalAlignment = UIControlContentHorizontalAlignment.Left
            deptmentProfile.backgroundColor = UIColor.whiteColor()
            deptmentProfile.titleEdgeInsets = UIEdgeInsetsMake(0, 40, 0, 0); //margin to the left
            cell.addSubview(deptmentProfile)
        }
        cell.accessoryType = UITableViewCellAccessoryType.None
    } 
    return cell
}
</code></pre>