Skip to content

Instantly share code, notes, and snippets.

@mchirico
Last active October 13, 2016 11:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mchirico/881faef02889d06ce712 to your computer and use it in GitHub Desktop.
Save mchirico/881faef02889d06ce712 to your computer and use it in GitHub Desktop.
Removing cells in tableview via a tag ... Taken from my MontCoEMS test app
//
// ViewController.swift
// MontCoEMS
//
// Created by Mike Chirico on 12/4/15.
// Copyright © 2015 Mike Chirico. All rights reserved.
//
//http://webapp.montcopa.org/eoc/cadinfo/livecadrss.asp
import UIKit
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet weak var tableView: UITableView!
/// A simple data structure to populate the table view.
let d = Montco()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
d.mystart()
tableView.dataSource = self
tableView.delegate = self
tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func button(sender: UIButton) {
d.flg = false
d.mystart()
tableView.reloadData()
}
@IBAction func buttonCheltenHam(sender: AnyObject) {
d.flg = true
d.mystart()
tableView.reloadData()
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return CGFloat(68.0)
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// Return the number of items in the sample data structure.
var count:Int?
if tableView == self.tableView {
count = d.table.count
}
return count!
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell:UITableViewCell?
if tableView == self.tableView {
cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath)
let title = d.table[indexPath.row].title
let desc = d.table[indexPath.row].desc
cell?.removeFromSuperview()
//cell!.textLabel?.text = previewDetail
//cell!.detailTextLabel?.text = "stuff...."
let bgView: UIView = UIView(frame: CGRectMake(0, 0, 367, 50))
bgView.backgroundColor = UIColor.grayColor()
bgView.layer.borderWidth = 3
bgView.alpha = 1
bgView.layer.cornerRadius = 9
bgView.tag = 100
if desc.rangeOfString("CHELTENHAM") != nil {
bgView.backgroundColor = UIColor.blueColor()
}
if desc.rangeOfString("ABINGTON") != nil {
bgView.backgroundColor = UIColor.greenColor()
}
let bgView2: UIView = UIView(frame: CGRectMake(4, 4, 200, 15))
bgView2.backgroundColor = UIColor.redColor()
bgView2.layer.borderWidth = 2
bgView2.alpha = 1
bgView2.layer.cornerRadius = 8
bgView2.tag = 50
let bgView3: UIView = UIView(frame: CGRectMake(10, 25, 350, 18))
bgView3.backgroundColor = UIColor.whiteColor()
bgView3.layer.borderWidth = 2
bgView3.alpha = 1
bgView3.layer.cornerRadius = 8
bgView3.tag = 51
let label = UILabel(frame: CGRectMake(0, 0, 200, 15))
//label.center = CGPointMake(160, 284)
label.textAlignment = NSTextAlignment.Center
label.textColor = UIColor.blackColor()
label.backgroundColor = UIColor.clearColor()
label.alpha = 10
label.text = title
label.tag = 101
label.font = UIFont(name: "Avenir", size: 9.0)
bgView2.addSubview(label)
bgView.addSubview(bgView2)
let label2 = UILabel(frame: CGRectMake(3, 3, 345, 10))
//label.center = CGPointMake(160, 284)
label2.textAlignment = NSTextAlignment.Center
label2.layer.cornerRadius = 10
label2.textColor = UIColor.blackColor()
label2.backgroundColor = UIColor.clearColor()
label2.alpha = 10
label2.text = desc
label2.tag = 102
label2.font = UIFont(name: "Avenir-Light", size: 8.0)
bgView3.addSubview(label2)
bgView.addSubview(bgView3)
cell!.viewWithTag(100)?.removeFromSuperview()
cell!.viewWithTag(101)?.removeFromSuperview()
cell!.viewWithTag(102)?.removeFromSuperview()
cell!.viewWithTag(50)?.removeFromSuperview()
cell!.viewWithTag(51)?.removeFromSuperview()
cell!.addSubview(bgView)
}
return cell!
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
print("did select: \(indexPath.row) ")
}
}
@mchirico
Copy link
Author

mchirico commented Dec 5, 2015

Here's how this looks...
You can find the parser code here.

screenshot 2015-12-05 17 04 32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment