セグエのない静的セル テーブル ビューがあります。これは、iPhone の [設定] -> [サウンド] -> [テキスト トーン] と同じです。チェックマークを実装して、そのシステム サウンドを別の ViewController から再生しても問題ありません。サウンド設定ViewControllerに戻ると、チェックマークがありません。ユーザーのデフォルトに indexPath.row と indexPath.section を保存しています。これを取得して変数に格納しています。以前に選択された行を示すために、「行用に 1 つ、セクション用に 1 つ」の indexPath を持つこれらの変数を使用するにはどうすればよいですか。Web、ビデオ、および StackoverFlow でソリューションを試しましたが、これを取得できないようです。
var rowSelected:Int = 0
var rowSection:Int = 0
override func viewDidLoad() {
super.viewDidLoad()
var defaults: NSUserDefaults = NSUserDefaults.standardUserDefaults()
if let soundIsNotNill = defaults.objectForKey("rowSelectedKey") as? Int{
self.rowSelected = defaults.objectForKey("rowSelectedKey") as! Int}
if let soundIsNotNill = defaults.objectForKey("rowSectionKey") as? Int{
self.rowSection = defaults.objectForKey("rowSectionKey") as! Int}
}
override func viewWillAppear(animated: Bool) {
println(" VDL rowSelected \(rowSelected)")
println(" VDL rowSection \(rowSection)")
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 13
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let tappedItem = indexPath.row
rowSelected = tappedItem
let section = indexPath.section
rowSection = section
for row in 0..<13 {
if let cell = tableView.cellForRowAtIndexPath(NSIndexPath(forRow: row, inSection: section)) {
cell.accessoryType = row == tappedItem ? .Checkmark : .None
}
}
println("didSelectRow rowSelected \(rowSelected)")
println("didSelectRow rowSection \(rowSection)")
var defaults: NSUserDefaults = NSUserDefaults.standardUserDefaults()
defaults.setObject(section, forKey: "rowSectionKey")
defaults.setObject(tappedItem, forKey: "rowSelectedKey")
defaults.synchronize()
saveSound()
}