support cell type: detailDesclosure
This commit is contained in:
parent
6411645568
commit
fca0b50990
3 changed files with 21 additions and 5 deletions
|
|
@ -13,7 +13,7 @@ enum CellDataType {
|
||||||
}
|
}
|
||||||
|
|
||||||
enum CellDataKey {
|
enum CellDataKey {
|
||||||
case type, title, link, footer
|
case type, title, link, footer, accessoryType, detailDisclosureAction, detailDisclosureData
|
||||||
}
|
}
|
||||||
|
|
||||||
class BasicStaticTableViewController: UITableViewController {
|
class BasicStaticTableViewController: UITableViewController {
|
||||||
|
|
@ -42,10 +42,20 @@ class BasicStaticTableViewController: UITableViewController {
|
||||||
let cell = UITableViewCell()
|
let cell = UITableViewCell()
|
||||||
let cellData = tableData[indexPath.section][indexPath.row]
|
let cellData = tableData[indexPath.section][indexPath.row]
|
||||||
cell.textLabel?.text = cellData[CellDataKey.title] as? String
|
cell.textLabel?.text = cellData[CellDataKey.title] as? String
|
||||||
cell.accessoryType = .disclosureIndicator
|
if let accessoryType = cellData[CellDataKey.accessoryType] as? UITableViewCellAccessoryType {
|
||||||
|
cell.accessoryType = accessoryType
|
||||||
|
} else {
|
||||||
|
cell.accessoryType = UITableViewCellAccessoryType.disclosureIndicator
|
||||||
|
}
|
||||||
return cell
|
return cell
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) {
|
||||||
|
let cellData = tableData[indexPath.section][indexPath.row]
|
||||||
|
let selector = cellData[CellDataKey.detailDisclosureAction] as? Selector
|
||||||
|
perform(selector, with: cellData[CellDataKey.detailDisclosureData])
|
||||||
|
}
|
||||||
|
|
||||||
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||||
tableView.deselectRow(at: indexPath, animated: true)
|
tableView.deselectRow(at: indexPath, animated: true)
|
||||||
let cellData = tableData[indexPath.section][indexPath.row]
|
let cellData = tableData[indexPath.section][indexPath.row]
|
||||||
|
|
|
||||||
|
|
@ -31,11 +31,17 @@ class OpenSourceComponentsTableViewController: BasicStaticTableViewController {
|
||||||
tableData.append([])
|
tableData.append([])
|
||||||
for item in openSourceComponents {
|
for item in openSourceComponents {
|
||||||
tableData[0].append(
|
tableData[0].append(
|
||||||
[CellDataKey.type: CellDataType.link, CellDataKey.title: item[0], CellDataKey.link: item[1]]
|
[CellDataKey.type: CellDataType.link, CellDataKey.title: item[0], CellDataKey.link: item[1], CellDataKey.accessoryType: UITableViewCellAccessoryType.detailDisclosureButton, CellDataKey.detailDisclosureAction: #selector(actOnDetailDisclosureButton(_:)), CellDataKey.detailDisclosureData: item[2]]
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
navigationItemTitle = "Open Source Components"
|
navigationItemTitle = "Open Source Components"
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func actOnDetailDisclosureButton(_ sender: Any?) {
|
||||||
|
if let link = sender as? String {
|
||||||
|
UIApplication.shared.open(URL(string: link)!, options: [:], completionHandler: nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,13 +27,13 @@
|
||||||
</constraints>
|
</constraints>
|
||||||
</imageView>
|
</imageView>
|
||||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Name" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="KvF-3d-EbG">
|
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Name" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="KvF-3d-EbG">
|
||||||
<rect key="frame" x="86" y="18" width="226" height="20.5"/>
|
<rect key="frame" x="86" y="18" width="226" height="21"/>
|
||||||
<fontDescription key="fontDescription" style="UICTFontTextStyleHeadline"/>
|
<fontDescription key="fontDescription" style="UICTFontTextStyleHeadline"/>
|
||||||
<nil key="textColor"/>
|
<nil key="textColor"/>
|
||||||
<nil key="highlightedColor"/>
|
<nil key="highlightedColor"/>
|
||||||
</label>
|
</label>
|
||||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="category1 > category2" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Ctk-b6-pjw">
|
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="category1 > category2" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Ctk-b6-pjw">
|
||||||
<rect key="frame" x="86" y="38.5" width="226" height="16"/>
|
<rect key="frame" x="86" y="39" width="226" height="16"/>
|
||||||
<fontDescription key="fontDescription" style="UICTFontTextStyleFootnote"/>
|
<fontDescription key="fontDescription" style="UICTFontTextStyleFootnote"/>
|
||||||
<color key="textColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
|
<color key="textColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
|
||||||
<nil key="highlightedColor"/>
|
<nil key="highlightedColor"/>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue