forked from AgoraIO/API-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewController.swift
More file actions
148 lines (127 loc) · 4.83 KB
/
ViewController.swift
File metadata and controls
148 lines (127 loc) · 4.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
//
// ViewController.swift
// APIExample
//
// Created by 张乾泽 on 2020/4/16.
// Copyright © 2020 Agora Corp. All rights reserved.
//
#if os(iOS)
import UIKit
#else
import Cocoa
#endif
struct MenuSection {
var name: String
var rows:[MenuItem]
}
struct MenuItem {
var name: String
var controller: String
}
class ViewController: AGViewController {
#if os(iOS)
var menus:[MenuSection] = [
MenuSection(name: "Basic", rows: [
MenuItem(name: "Join a channel (Video)", controller: "JoinChannelVideo"),
MenuItem(name: "Join a channel (Audio)", controller: "JoinChannelAudio")
]),
MenuSection(name: "Anvanced", rows: [
MenuItem(name: "RTMP Streaming", controller: "RTMPStreaming"),
MenuItem(name: "RTMP Injection", controller: "RTMPInjection"),
MenuItem(name: "Video metadata", controller: "VideoMetadata")
]),
]
#else
var menus:[MenuSection] = [
MenuSection(name: "Basic", rows: [
MenuItem(name: "Join a channel (Video)", controller: "JoinChannelVideoMain"),
MenuItem(name: "Join a channel (Audio)", controller: "JoinChannelAudioMain")
])
]
@IBOutlet weak var sectionTableView: NSTableView!
@IBOutlet weak var subTableView: NSTableView!
var sectionSelected = 0
override func viewDidLoad() {
super.viewDidLoad()
sectionTableView.selectRowIndexes(IndexSet(integer: 0), byExtendingSelection: false)
}
override func prepare(for segue: NSStoryboardSegue, sender: Any?) {
if let vc = segue.destinationController as? BaseViewController {
vc.closeDelegate = self
}
}
#endif
}
#if os(iOS)
extension ViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return menus[section].rows.count
}
func numberOfSections(in tableView: UITableView) -> Int {
return menus.count
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return menus[section].name
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellIdentifier = "menuCell"
var cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier)
if cell == nil {
cell = UITableViewCell(style: .default, reuseIdentifier: cellIdentifier)
}
cell?.textLabel?.text = menus[indexPath.section].rows[indexPath.row].name
return cell!
}
}
extension ViewController: UITableViewDelegate {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
let name = "\(menus[indexPath.section].rows[indexPath.row].controller)"
let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let newViewController = storyBoard.instantiateViewController(withIdentifier: name)
self.navigationController?.pushViewController(newViewController, animated: true)
}
}
#else
extension ViewController: NSTableViewDelegate, NSTableViewDataSource {
func numberOfRows(in tableView: NSTableView) -> Int {
if tableView == sectionTableView {
return menus.count
} else {
return menus[sectionSelected].rows.count
}
}
func tableView(_ tableView: NSTableView, shouldSelectRow row: Int) -> Bool {
if tableView == sectionTableView {
sectionSelected = row
subTableView.reloadData()
return true
} else {
let name = "\(menus[sectionSelected].rows[row].controller)"
self.performSegue(withIdentifier: name, sender: nil)
return false
}
}
func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
if tableView == sectionTableView {
let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "SectionCell"),
owner: nil) as! NSTableCellView
cell.textField?.text = menus[row].name
return cell
} else {
let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "SubCell"),
owner: nil) as! NSTableCellView
cell.textField?.text = menus[sectionSelected].rows[row].name
return cell
}
}
func tableView(_ tableView: NSTableView, heightOfRow row: Int) -> CGFloat {
return 36
}
}
extension ViewController: ViewControllerCloseDelegate {
func viewControllerNeedClose(_ liveVC: AGViewController) {
liveVC.view.window?.contentViewController = self
}
}
#endif