Post

Replies

Boosts

Views

Activity

Reply to Pushed over tabs
Here you go: import UIKit class Categories: UIViewController {     @IBOutlet weak var CategoryList: UITableView!          let names = [         "Dad Jokes",         "Virtual Assistant Jokes",         "Knock Knock Jokes"     ]          override func viewDidLoad() {         super.viewDidLoad()                  CategoryList.delegate = self         CategoryList.dataSource = self     }     override func prepare(for segue: UIStoryboardSegue, sender: Any?) {         let backItem = UIBarButtonItem()         backItem.title = "Back"         navigationItem.backBarButtonItem = backItem // This will show in the next view controller being pushed     }} extension Categories: UITableViewDelegate {          func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {         print(indexPath.row)         let row = indexPath.row         if row == 0 {             self.performSegue(withIdentifier: "Dad Jokes", sender: self)         }else if row == 1 {             self.performSegue(withIdentifier: "Assistant Jokes", sender: self)         }else if row == 2 {             self.performSegue(withIdentifier: "Knock Knock Jokes", sender: self)         }         tableView.deselectRow(at: indexPath, animated: true)} } extension Categories: UITableViewDataSource {          func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) - Int {         return names.count     }          func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) - UITableViewCell {         let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)                  cell.textLabel?.text = names[indexPath.row]                  return cell     } }
Mar ’21
Reply to Passing data from an App VC to its widget
You pretty much have to. I use: import UIKit import WidgetKit ... //code //code for widget UDM.shared.UserDefaults(suiteName: "group.whatever")?.setValue(urCode, forKey: "I'm a key") WidgetCenter.shared.reloadAllTimelines() Note: you have to set up a shared group between the app and the widget in the capabilities of the targets.
Topic: Programming Languages SubTopic: Swift Tags:
Mar ’21