Showing posts with label uitableview. Show all posts
Showing posts with label uitableview. Show all posts

Tuesday, October 11, 2016

Table Headers and Footers

Drag and drop UIViews on to a UITableView on the storyboard.
Tip: Add a prototype cell to the table view first. Then drag and drop the UIView above the prototype cell for a header or below the prototype cell for the footer.

You can then remove the prototype cell after you are done adding the header and/or footer.


(Xcode 8, Swift 3.0)

Thursday, September 29, 2016

Refresh Control on TableView

You can use the table view's new refreshControl property to set your UIRefreshControl.
 
override func viewDidLoad() {
    super.viewDidLoad()
    
    tableView.delegate = self
    tableView.dataSource = self
    
    refreshControl.addTarget(self, action: #selector(ViewController.refreshData), 
        for: UIControlEvents.valueChanged)
    
    if #available(iOS 10.0, *) {
        tableView.refreshControl = refreshControl
    } else {
        tableView.addSubview(refreshControl)
    }
}

func refreshData() {
    // Refresh data code
    
    tableView.reloadData()
    refreshControl.endRefreshing()
}
 


(Xcode 8, Swift 3.0)

Thursday, September 8, 2016

Dynamic Row Height

There are 3 main things you need for dynamic height:
  • Set estimatedRowHeight
  • Set rowHeight to UITableViewAutomaticDimension
  • Set the label's numberOfLines property in your cell to zero
 
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

    @IBOutlet weak var tableView: UITableView!
    
    var tableData: [String] = ["Rod",
                               "Mark",
                               "Lem is from the Philippines. He is a Filipino!",
                               "Evans"]
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        tableView.delegate = self
        tableView.dataSource = self
        
        tableView.estimatedRowHeight = 44;
        tableView.rowHeight = UITableViewAutomaticDimension;
    }
    
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) 
          -> Int {
        return tableData.count
    }
    
    func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath)
        -> UITableViewCell {
            var cell = tableView.dequeueReusableCellWithIdentifier("cell")
            
            if cell == nil {
                cell = UITableViewCell(style: .Default, reuseIdentifier: "cell");
            }
            cell!.textLabel?.text = tableData[indexPath.row]
            cell!.textLabel?.numberOfLines = 0
            return cell!
    }
}
 


(Xcode 7.3, Swift 2.2)

SwiftUI Search & Filter with Combine - Part 3 (iOS, Xcode 13, SwiftUI, 2...

In part 3 of the Searchable video series, I show you how to use Combine in #SwiftUI for the search and filter logic connected to the searcha...