Post

Replies

Boosts

Views

Activity

Reply to Navigation title with LayoutConstraints Warnings in Console
Testing your code with Xcode 12.5.1 on an iOS Simulator or an actual device of iOS 14.7.1, I could not see any messages in the debug console. I'm not sure if this is because of my environment or your environment. Those may be ignorable (so called log noise) if they does not affect the app harmfully. You can send a bug report to Apple with attaching your project and describing your environment precisely.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Sep ’21
Reply to How to save the state of a Switch
I want to save the state when there is a change to the switch state Please modify the code above as follows: class Settings: UIViewController, UITableViewDelegate, UITableViewDataSource { //... override func viewDidLoad() { super.viewDidLoad() table.dataSource = self // Load `cellStates` if you need it... NotificationCenter.default.addObserver(self, selector: #selector(switchDidChange), name: .switchDidChange, object: nil) } @objc func switchDidChange(_ notification: Notification) { // Save `cellStates`... } } class SettingsCustomCell: UITableViewCell { //... @objc func switchValueChanged(sender: UISwitch) { state?.settingValue = sender.isOn NotificationCenter.default.post(name: .switchDidChange, object: self) } } extension Notification.Name { static let switchDidChange = Notification.Name("switchDidChange") }
Topic: Programming Languages SubTopic: Swift Tags:
Sep ’21
Reply to Array Elements - Getting Control
Unfortunately, the forums lack very important feature -- editing old posts. You may need to use Your Answer to show additional info. In addition, please show the complete definition of your Data. (Generally, you should better not use the same type name as very popular standard type names.)
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Sep ’21
Reply to List Sections
Thanks for showing the code. I could have reproduce the similar layout with the new code. (I used simplified layout because I could not make it work but that was enough. By the way, you should better follow the naming rule of Swift when you write code in Swift.) With this part: List(data) { data in Section(header: Text("GroupPicks")) { layout(data: data) } } You are trying to add a section to each row of your List. Which causes the result as shown in your previous screen shot. Putting Section inside List(data) { ... } does not make sense. Please try something like this: if data.count == 0 { Text("No Picks Found") } else { List { Section(header: Text("GroupPicks")) { ForEach(data) { data in layout(data: data) } } } .listStyle(GroupedListStyle()) //.listStyle(PlainListStyle()) //.listStyle(InsetListStyle()) }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Sep ’21
Reply to How to save the state of a Switch
OK so I rewrote some code, Thanks, that makes sense a little more than the original code. But still, a few things: Having UI elements as data would not be a good practice You use textLabel although you define settingLabel in your custom cell You may need to reflect the state of each switch to some sort of data source. Please try something like this. Prepare a custom cell which can reflect the changes of switch: class SettingsCustomCell: UITableViewCell { @IBOutlet weak var settingLabel: UILabel! @IBOutlet weak var quickAddSwitch: UISwitch! var state: SettingsState? { didSet { if let state = state { settingLabel.text = state.settingLabel quickAddSwitch.isOn = state.settingValue } } } override func awakeFromNib() { quickAddSwitch.addTarget(self, action: #selector(switchValueChanged), for: .valueChanged) } @objc func switchValueChanged(sender: UISwitch) { state?.settingValue = sender.isOn } } class SettingsState { var settingLabel: String var settingValue: Bool init(settingLabel: String, settingValue: Bool) { self.settingLabel = settingLabel self.settingValue = settingValue } } And use it like this: class Settings: UIViewController, UITableViewDelegate, UITableViewDataSource { var cellStates: [SettingsState] = [ SettingsState(settingLabel: "Quick Add", settingValue: false), ] func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return cellStates.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = table.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! SettingsCustomCell cell.state = cellStates[indexPath.row] return cell } @IBOutlet weak var table: UITableView! override func viewDidLoad() { super.viewDidLoad() table.dataSource = self // Load `cellStates` if you need it... // (I could not find when you want to save it.) } }
Topic: Programming Languages SubTopic: Swift Tags:
Sep ’21
Reply to Calling a View
It depends on many things, but one possible way is to use sheet or fullScreenCover: struct ContentView: View { @State var search: String = "abc" @State var isPresented: Bool = false var body: some View { VStack { Button(action: { self.isPresented = true }) { Text("Search") } } .fullScreenCover(isPresented: $isPresented, content: { MyViewB(keyword: self.search) }) } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Sep ’21
Reply to How to write AVAudioBuffer to a file?
How should plain AVAudioBuffer be handled? AVAudioBuffer is sort of an abstract super type of AVAudioPCMBuffer. You can check its type and cast it to AVAudioPCMBuffer. And as far as I tried, writeUtterance:toBufferCallback: always uses AVAudioPCMBuffer as buffer. You may need to abandon further processing if it was not.
Topic: Media Technologies SubTopic: Audio Tags:
Sep ’21