Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView - I want to display blank cell

I set up my tableView and has two springVar as shown in the image below. I want my tableview to show empty cells after the two springVar so that my solve bar is at the bottom of the screen. Any advices on how to go about it? My code is below.

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return springVar.count
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let cellIdentifier = "Cell"
    var cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) as? UITableViewCell

    if cell == nil {
        cell = UITableViewCell(style: UITableViewCellStyle.Value2, reuseIdentifier: cellIdentifier)
    }
    cell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "cell")

    var data : NSManagedObject = springVar[indexPath.row] as! NSManagedObject
    cell!.textLabel!.text = "Spring \(indexPath.row + 1)"

    var force : Float = data.valueForKey("force") as! Float
    var stiffness : Float = data.valueForKey("stiffness") as! Float
    cell!.detailTextLabel!.text = "Force =\(force) \t Stiffness =\(stiffness)"
    cell!.detailTextLabel!.textColor = UIColor .darkGrayColor()

    return cell!
}

TableImage

like image 320
Cherry_thia Avatar asked Sep 07 '25 03:09

Cherry_thia


2 Answers

i think this maybe helpfull

if indexPAth.row / 2 == 0
{
    return UITableViewCell()
    // u can customize ur cell to show a button or anything else
}

this show a custom/blank cell after each 2 cell,(odd)

like image 87
Saeed-rz Avatar answered Sep 09 '25 22:09

Saeed-rz


You can add Footer view in your tableView this way:

override func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
    let footerView = UIView(frame: CGRectMake(0, 0, tableView.frame.size.width, 40))
    footerView.backgroundColor = UIColor.whiteColor()

    //add button in your footer view
    var button = UIButton(frame: CGRectMake(0, 0, 75, 30))
    button.setTitle("Solve", forState: UIControlState.Normal)
    button.setTitleColor(UIColor.brownColor(), forState: UIControlState.Normal)
    button.addTarget(self, action: "buttonTapAction:", forControlEvents: UIControlEvents.TouchUpInside)
    footerView.addSubview(button)

    return footerView
}

override func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
    return 40.0
}

And your result will be:

enter image description here

like image 21
Dharmesh Kheni Avatar answered Sep 09 '25 22:09

Dharmesh Kheni