Skip to content

Commit

Permalink
Add "text" property to "net.swipe.list" type item to display the text…
Browse files Browse the repository at this point in the history
… as a subtitle.
  • Loading branch information
Yoichi Tagaya committed Dec 12, 2016
1 parent fed1292 commit 5caa53d
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions browser/SwipeTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -170,19 +170,23 @@ class SwipeTableViewController: UIViewController, UITableViewDelegate, UITableVi
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = dequeueCell()

// Configure the cell...
let section = self.sections[indexPath.section]
guard let items = section["items"] as? [[String:Any]] else {
return cell
return dequeueCell(style: .default)
}
let item = items[indexPath.row]
let text = item["text"] as? String
let cell = dequeueCell(style: text == nil ? .default : .subtitle)

// Configure the cell...
if let title = item["title"] as? String {
cell.textLabel!.text = title
} else if let url = item["url"] as? String {
cell.textLabel!.text = url
}
if let text = text {
cell.detailTextLabel!.text = text
}
if let icon = item["icon"] as? String,
let url = URL.url(icon, baseURL: self.url),
let urlLocal = self.prefetcher.map(url),
Expand All @@ -209,13 +213,17 @@ class SwipeTableViewController: UIViewController, UITableViewDelegate, UITableVi
return section["title"] as? String
}

private func dequeueCell() -> UITableViewCell {
if let cell = tableView.dequeueReusableCell(withIdentifier: "foo") {
private static let cellIdentifiers = [UITableViewCellStyle.default: "default", .subtitle: "subtitle"] // value1 and value2 styles are not supported yet.

private func dequeueCell(style: UITableViewCellStyle) -> UITableViewCell {
let identifier = SwipeTableViewController.cellIdentifiers[style]!
if let cell = tableView.dequeueReusableCell(withIdentifier: identifier) {
cell.textLabel?.text = nil
cell.detailTextLabel?.text = nil
cell.imageView?.image = nil
return cell
} else {
return UITableViewCell(style: .default, reuseIdentifier: "foo")
return UITableViewCell(style: style, reuseIdentifier: identifier)
}
}

Expand Down

0 comments on commit 5caa53d

Please sign in to comment.