How Can I Refresh The Background Theme? - objective-c

I Will Going Done Two Things On It.
First set Theme colour On All VC and second changing my currency from INR TO USD or vice versa.
I Have This View Controller named As Settings VC.
1) I am going to change the theme of the VC
2) It will changed but for that I need to go back from this view controller. It Will Never changed Here Automatically.
3) Can Anyone Help me For this to change it here automatically without navigating any other VC?
Here I Is My Code...
import UIKit
class SettingsVC: UIViewController {
#IBOutlet weak var themeColorSeg: UISegmentedControl!
#IBOutlet weak var Currency: UISegmentedControl!
override func viewDidAppear(_ animated: Bool){
setThemeOnVC(View: self.view)
}
override func viewDidLoad() {
super.viewDidLoad()
themeColorSeg.selectedSegmentIndex = getTheme()
Currency.selectedSegmentIndex = getCurrency()
}
#IBAction func saveAction(_ sender: Any) {
setTheme(themeCode: themeColorSeg.selectedSegmentIndex)
setCurrency(CurrencyCode: Currency.selectedSegmentIndex)
navigationController?.present(Utilities().configPopup(title: "Saved", message: "Settings Seved Successfully!"), animated: true, completion: nil)
}
}
Check Video Here

on saveAction, add below line too
setThemeOnVC(View: self.view)

Related

Picker View - Textfield not updating

I am trying to make a drop down list and is experimenting with using the PickerView. But i could not find a way to update the textfield after selecting the items in the Picker View.
I suspect the “didSelectRow” of the pickerView function wasn’t called at all though I don’t know how to check it. (I tried to print the selected row but nothing happens).
This is what I did at the Interface Builder :
make a textfield.
drag the Picker View from Library to the interface.
connect the outlets and PickerView.
ctl drag the PickerView to the yellow icon at View Controller and select delegate and datasource.
ctl drat the textfield to the yellow icon at the View Controller and select delegate.
hope someone can kindly help.
following are my codes :
import UIKit
class ViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {
#IBOutlet weak var pickerBox: UIPickerView!
#IBOutlet weak var textBox: UITextField!
var list = ["Item 1", "Item 2", "Item 3"]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
func numberOfComponents(in pickerView: UIPickerView) -> Int{
return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return list.count
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
var listingTypesArray = Array(list)
return listingTypesArray[row]
}
func pickerView(pickerView: UIPickerView!, didSelectRow row: Int, forComponent component: Int) {
self.textBox.text = list[row]
print("Row: \(row)")
}
}
You forgot to add delegate and datasource
override func viewDidLoad()
{
super.viewDidLoad()
// Do any additional setup after loading the view.
self. pickerBox.delegate = self
self. pickerBox.dataSource = self
}

how do I link a button to the webview of another controller having a link that changes based on the cell pressed?

I have a button that needs to open a web view on another controller in modally. currently the button executes the code you see below. I would like the button to open the webview directly. the link changes because it is an rss reader and therefore, based on the cell pressed, changes the link of the button that must open the webview.
this is the code that manages the controller that appears after the cell has been pressed
class FeedItemWebViewController: UIViewController, UIWebViewDelegate {
#IBOutlet weak var textView: UITextView!
var link: String? = nil
var descriptionTesto:String? = nil
override func viewDidLoad() {
super.viewDidLoad()
self.textView.text = descriptionTesto
}
#IBAction func apri(_ sender: UIBarButtonItem) {
guard let url = URL(string: self.link ?? "") else { return }
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
}
here is where it manages the controller where I entered the webview
class OpenSafariController: UIViewController, UIWebViewDelegate {
#IBOutlet weak var myWebView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
}
#IBAction func ritornaLista(_ sender: UIBarButtonItem) {
self.presentingViewController?.presentingViewController?.dismiss(animated: false, completion: nil)
}
}
delete the webview controller that is not needed. import SafariServices. here is the code to put on the button
#IBAction func apri(_ sender: UIBarButtonItem) {
let svc = SFSafariViewController(url: URL(string: self.link ?? "")!)
self.present(svc, animated: true, completion: nil)
}

Xib not showing up in view

I have a Xib file trying to set it up with my storyboard. Everything in the Xib file is fine, but for some reason, it's not showing. I imported a file from GitHub which is set to my Xib, it's in Objective-C and I set the bridging, no errors. But when I run it nothing shows its blank. Did I not set something in the View Controller? Everything is done programmatically and I just set the class in storyboard.
Screenshot of storyboard:
What the simulator gives me when I push to the ViewController:
This is what I'm supposed to see:
What I am trying to implement -
https://github.com/jberlana/JBCroppableView
My XIB class
import UIKit
class CropViewXIB: UIView {
#IBOutlet weak var ImageView: JBCroppableImageView!
#IBAction func SubAction(_ sender: Any) {
ImageView.removePoint()
}
#IBAction func AddAction(_ sender: Any) {
ImageView.addPoint()
}
#IBAction func UndoAction(_ sender: Any) {
ImageView.reverseCrop()
}
#IBAction func CropAction(_ sender: Any) {
ImageView.crop()
}
override init(frame: CGRect) {
super.init(frame: frame)
commomInit()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
commomInit()
}
private func commomInit(){
Bundle.main.loadNibNamed("CropViewXIB", owner: self, options: nil)
self.addSubview(ImageView)
ImageView.frame = self.bounds
ImageView.autoresizingMask = [.flexibleHeight, .flexibleWidth]
}
}
my view controller
import UIKit
class ViewController: UIViewController {
#IBOutlet weak var cropView: CropViewXIB!
override func viewDidLoad() {
super.viewDidLoad()
}
}
The issue is that you didn't actually get the parent view for your UINib object.
Bundle.main.loadNibNamed("CropViewXIB", owner: self, options: nil)
The line above returns an [Any] in your case you aren't even using the view that it is returning. so the idea is to get the first object from it and cast it as UIView such as:
Bundle.main.loadNibNamed("CropViewXIB", owner: self, options: nil)?.first as? UIView
Personally this is how I interact with a Nib. I create a view property of type UIView that can be referred as the parent view for the nib, and all subviews get added to it instead of self.
Something like this:
final class SomeNibView: UIView {
public var view: UIView!
private func setup() { // called to the initializer
// grab the views from loadNibNamed
guard let _view = Bundle.main.loadNibNamed("name", owner: self, options: nil)?.first as? UIView else { return }
// set it to our view property
view = _view
// add this property to the nib subview aka self
addSubview(view)
view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
}
private func addMulitpleSubviews() {
// instead of doing self.addSubview(....) when it comes to add other subviews
// you'll do this view.addSubview(....)
}
}
Try to load xib using programming not using storyboard.
override func viewDidLoad()
{
super.viewDidLoad()
guard let yourXIB = Bundle.main.loadNibNamed("CropViewXIB", owner: self, options: nil)?.first as? CropViewXIB else { return}
self.view.addSubview(yourXIB)
}

How do i refer to a variable that was made in another view controller in swift

How do i add the text to from my textfield into an array that is made in another ViewController.
class FirstViewController: UIViewController, UITableViewDelegate {
var thingsToDo = []
class SecondViewController: UIViewController {
#IBOutlet weak var enterTask: UITextField!
#IBAction func addtask(sender: AnyObject) {
thingsToDo += enterTask.text
}
You can use the prepareForSegue-method to pass objects to another viewcontroller. First you have to add global variable in your SecondViewController.
var theThingsToDo:[AnyObject]!
Then, in your FirstViewController, you can use the prepareForSegue-method and pass the value from your FirstViewController to your SecondViewController. It is important that you set the name of the segue in your Storyboard.
You can find the segue-identifier in the top right corner of Xcode:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?){
if segue.identifier == "yourSegueIdentifier" {
// Value of the FirstViewControllers variable 'thingsToDo' will be sent to the SecondViewController
(segue.destinationViewController as SecondViewController).theThingsToDo = thingsToDo
}
}
#IBAction func addtask(sender: AnyObject) {
theThingsToDo += enterTask.text
}

Why isn't UIKeyboard appearing when I tap inside a UITextField in swift?

Is this something to do with swift?
I've set up a controller without any connection to another but it is instantiated using it's storyboard ID.
Associated class file:
import Foundation
import UIKit
class SignUpViewController : UIViewController, UITextFieldDelegate {
#IBOutlet weak var companyField: UITextField!
#IBOutlet weak var emailField: UITextField!
#IBOutlet weak var passwordField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
}
#IBAction func loginButtonTapped(sender: UIButton) {
}
#IBAction func forgotPasswordButtonTapped(sender: UIButton) {
}
#IBAction func signUpButtonTapped(sender: UIButton) {
}
}
This is how I present the sign up controller:
#IBAction func signUpButtonTapped(sender: UIButton) {
let signUpViewController = self.storyboard?.instantiateViewControllerWithIdentifier("signUpViewControllerSB") as SignUpViewController
self.presentViewController(signUpViewController, animated: true, completion: nil)
}
I tap in any text field and get the flashing cursor but no keyboard appears.
What am I missing?
Prior to swift I could just add textfields, run simulator and the keyboard would pop up.
I'm sure I've done everything correctly.
Check these settings.Go to
iOS Simulator -> Hardware -> Keyboard->Toggle Software Keyboard
also
iOS Simulator -> Hardware -> Keyboard-> Uncheck Connect Hardware Keyboard