@@ -3,6 +3,8 @@ import UIKit
33class SettingsViewController : UIViewController , UITableViewDelegate , UITableViewDataSource {
44
55 let tableView = UITableView ( frame: . zero, style: . insetGrouped)
6+ let options = [ NSLocalizedString ( " Reboot_Device_text " , comment: " " ) , NSLocalizedString ( " Respring_text " , comment: " " ) ]
7+ var selectedOption : String = NSLocalizedString ( " Reboot_Device_text " , comment: " " ) // 默认选项
68
79 // 每个分组的小标题
810 let sectionTitles = [
@@ -16,9 +18,9 @@ class SettingsViewController: UIViewController, UITableViewDelegate, UITableView
1618 let sections = [
1719 [ NSLocalizedString ( " Show_Alert_Before_Starting_text " , comment: " " ) , NSLocalizedString ( " Display_Root_Permission_text " , comment: " " ) ] ,
1820 [ NSLocalizedString ( " Respring_text " , comment: " " ) , NSLocalizedString ( " Home_Screen_Quick_Actions_text " , comment: " " ) ] ,
19- [ NSLocalizedString ( " Enable_text " , comment: " " ) , NSLocalizedString ( " Time_text " , comment: " " ) , NSLocalizedString ( " Action_text " , comment: " " ) ] ,
21+ [ NSLocalizedString ( " Enable_text " , comment: " " ) , NSLocalizedString ( " Time_text " , comment: " " ) , NSLocalizedString ( " Action_text " , comment: " " ) , NSLocalizedString ( " When_Open_Application_To_Action_text " , comment : " " ) ] ,
2022// [String(localized: "Version_text"),"Github"]
21- [ NSLocalizedString ( " Version_text " , comment: " " ) , " Github " ]
23+ [ NSLocalizedString ( " Version_text " , comment: " " ) , " GitHub " , NSLocalizedString ( " Special_Thanks_text " , comment : " " ) ]
2224 ]
2325
2426 // UserDefaults 键
@@ -66,14 +68,14 @@ class SettingsViewController: UIViewController, UITableViewDelegate, UITableView
6668 // 设置单元格的文本
6769 cell. textLabel? . text = sections [ indexPath. section] [ indexPath. row]
6870 cell. textLabel? . numberOfLines = 0 // 允许文本过长时换行
71+ cell. selectionStyle = . none // 禁用选中效果
6972
7073 switch indexPath. section {
7174 case 0 , 1 :
7275 // 创建 UISwitch 控件
7376 let switchView = UISwitch ( frame: . zero)
7477 switchView. tag = indexPath. section
7578 switchView. addTarget ( self , action: #selector( self . switchChanged ( _: ) ) , for: . valueChanged)
76-
7779 // 根据不同的设置项初始化开关状态
7880 if indexPath. section == 0 {
7981 switchView. isOn = UserDefaults . standard. bool ( forKey: self . warningKey)
@@ -85,7 +87,7 @@ class SettingsViewController: UIViewController, UITableViewDelegate, UITableView
8587
8688 cell. accessoryView = switchView
8789 case 2 : // 倒计时器的设置
88- if indexPath. row == 0 { // Enable
90+ if indexPath. row == 0 || indexPath . row == 3 { // Enable
8991 let switchView = UISwitch ( frame: . zero)
9092 switchView. tag = indexPath. section
9193 switchView. addTarget ( self , action: #selector( self . switchChanged ( _: ) ) , for: . valueChanged)
@@ -95,22 +97,22 @@ class SettingsViewController: UIViewController, UITableViewDelegate, UITableView
9597 // 添加 UIStepper
9698 cell = UITableViewCell ( style: . value1, reuseIdentifier: " cell " )
9799 cell. textLabel? . text = sections [ indexPath. section] [ indexPath. row]
98- cell. detailTextLabel? . text = " 1秒 " // 默认值
100+ cell. detailTextLabel? . text = String . localizedStringWithFormat ( NSLocalizedString ( " Seconds_text " , comment : " Time in seconds " ) , 5 ) // 默认值
99101 let stepper = UIStepper ( )
100102 stepper. minimumValue = 0 // 最小值
101103 stepper. maximumValue = 15 // 最大值
102- stepper. value = 1 // 初始值
104+ stepper. value = 5 // 初始值
103105 stepper. stepValue = 1 // 每次加减步长
104-
105106 // 添加事件监听
106107 stepper. addTarget ( self , action: #selector( self . stepperValueChanged ( _: ) ) , for: . valueChanged)
107108
108109 // 设置 UIStepper 为 cell 的 accessoryView
109110 cell. accessoryView = stepper
110111 } else if indexPath. row == 2 {
111- //
112-
113-
112+ cell = UITableViewCell ( style: . value1, reuseIdentifier: " cell " )
113+ cell. textLabel? . text = sections [ indexPath. section] [ indexPath. row]
114+ cell. detailTextLabel? . text = selectedOption // 显示当前选中的选项
115+ cell. accessoryType = . disclosureIndicator // 添加右侧箭头
114116 }
115117 case 3 :
116118 if indexPath. row == 0 {
@@ -120,9 +122,11 @@ class SettingsViewController: UIViewController, UITableViewDelegate, UITableView
120122 cell. detailTextLabel? . text = version
121123 cell. selectionStyle = . none
122124 cell. accessoryType = . none
125+ } else if indexPath. row == 1 || indexPath. row == 2 {
126+ cell. accessoryType = . disclosureIndicator
127+ cell. selectionStyle = . default // 启用选中效果
123128 }
124129
125-
126130 default : break
127131
128132 }
@@ -131,7 +135,6 @@ class SettingsViewController: UIViewController, UITableViewDelegate, UITableView
131135 }
132136
133137 // MARK: - UISwitch 事件处理
134-
135138 @objc func switchChanged( _ sender: UISwitch ) {
136139 if sender. tag == 0 {
137140 // 第一个设置项:执行操作前发出警告
@@ -147,13 +150,48 @@ class SettingsViewController: UIViewController, UITableViewDelegate, UITableView
147150 // 找到 UIStepper 所在的单元格
148151 if let cell = sender. superview as? UITableViewCell {
149152 // 更新 detailTextLabel 显示当前值
150- cell. detailTextLabel? . text = " \( Int ( sender. value) ) "
153+ cell. detailTextLabel? . text = String . localizedStringWithFormat ( NSLocalizedString ( " Seconds_text " , comment : " " ) , Int ( sender. value) )
151154 }
152155 }
153156
154- // MARK: - UITableViewDelegate
157+ // MARK: - UITableViewDelegate 点击item的事件
155158 func tableView( _ tableView: UITableView , didSelectRowAt indexPath: IndexPath ) {
156- tableView. deselectRow ( at: indexPath, animated: true )
159+ if indexPath. section == 2 && indexPath. row == 2 {
160+ let actionSheet = UIAlertController ( title: NSLocalizedString ( " Choose_An_Action_text " , comment: " " ) , message: nil , preferredStyle: . actionSheet)
161+
162+ // 添加选项
163+ for option in options {
164+ let action = UIAlertAction ( title: option, style: . default) { _ in
165+ self . selectedOption = option
166+ tableView. reloadRows ( at: [ indexPath] , with: . none) // 更新单元格显示
167+ }
168+ actionSheet. addAction ( action)
169+ }
170+
171+ // 添加取消按钮
172+ let cancelAction = UIAlertAction ( title: NSLocalizedString ( " Cancel_text " , comment: " " ) , style: . cancel, handler: nil )
173+ actionSheet. addAction ( cancelAction)
174+
175+ // 显示弹窗
176+ if let popover = actionSheet. popoverPresentationController {
177+ // 处理 iPad 的情况
178+ popover. sourceView = tableView
179+ popover. sourceRect = tableView. rectForRow ( at: indexPath)
180+ popover. permittedArrowDirections = . any
181+ }
182+
183+ present ( actionSheet, animated: true , completion: nil )
184+ } else if indexPath. section == 3 && indexPath. row == 1 {
185+ tableView. deselectRow ( at: indexPath, animated: true )
186+ if let url = URL ( string: " https://github.com/DevelopCubeLab/RebootTools " ) {
187+ UIApplication . shared. open ( url, options: [ : ] , completionHandler: nil )
188+ }
189+ } else if indexPath. section == 3 && indexPath. row == 2 {
190+ tableView. deselectRow ( at: indexPath, animated: true )
191+ if let url = URL ( string: " https://m.xiaobovlog.cn/ " ) {
192+ UIApplication . shared. open ( url, options: [ : ] , completionHandler: nil )
193+ }
194+ }
157195 }
158196
159197 // MARK: - 设置每个分组的标题
0 commit comments