Is any possible to add background picture to specify Eureka Form? - eureka-forms

I want add background to the form itself, but I can't figure out how to do it.
class ChallengeViewController: FormViewController {
override func viewDidLoad() {
super.viewDidLoad()
//how to add background picture to the form???
form +++
TextRow("title").cellSetup {cell,row in
cell.textField.placeholder = "Task title"
}
}
}
How to work around it??? thanks :)

I know!
there are one pop name tableView...

Related

Mac NSTextField won't resign firstResponder

I have a window with some NSTextFields. When I click in one and edit the value and press return, I want the focus to go back to what it was before. I don't want the blue ring around the text field and I don't want further keystrokes going to that text field. I would have thought this would happen automatically.
I tried these, and none of them work
sender.resignFirstResponder()
sender.window?.makeFirstResponder(nil)
InspectorWindowController.window?.makeFirstResponder(nil)
AnotherWindowController.window?.becomeFirstResponder()
I'm doing these at the end of my IBAction associated with the text field. Maybe I have to do it from somewhere else?
Thanks
I figured this out. I guess the sent action is happening on another thread. So you have to call makeFirstResponder using Dispatch async.
DispatchQueue.main.async { //omg
sender.window?.makeFirstResponder(nil)
}
I needed to dismiss first responder in my SwiftUI macOS app and here what I found working in a way I need:
func controlTextDidEndEditing(_ obj: Notification) {
DispatchQueue.main.async {
guard let window = self.textField.window else {
return
}
// https://stackoverflow.com/questions/5999148/how-to-determine-whether-an-nssearchfield-nstextfield-has-input-focus
// We need to make sure that our text field is still first responder.
guard let textView = window.firstResponder as? NSTextView,
textView.delegate === self.textField else {
return
}
window.makeFirstResponder(nil)
}
}

Dismissing keyboard in UITextField with RAC(5)?

Newbie to ReactiveCocoa and ReactiveSwfit here... Sorry if the answer is obvious.
I am trying to adapt the Start Developing iOS Apps with Swift sample to ReactiveSwift / ReactiveCocoa, and I am running into an issue with "translating" the UITextField's Delegate method -- which gets rid of the keyboard and essentially ends the editing (so I can capture the text field in the mealNameLabel) :
func textFieldShouldReturn(_ textField: UITextField) -> Bool
I am using
nameTextField.reactive.textValues.observeValues { value in
viewModel.mealName.swap(value ?? "")
}
// Setup bindings to update the view's meal label
// based on data from the View Model
mealNameLabel.reactive.text <~ viewModel.mealLabel
to get the value from the text field into the view model and percolate the view model's label back to the UILabel (convoluted...)
That works fine, as long as I maintain the viewController as the UITextField's delegate and I still implement the method depicted in the tutorial and mentioned above. Essentially :
override func viewDidLoad() {
super.viewDidLoad()
nameTextField.delegate = self
// view controller logic
...
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
// Hide the keyboard.
textField.resignFirstResponder()
return true
}
I tried using
nameTextField.reactive.controlEvents
but that failed miserably due to my lack of understanding of controlEvents (docs anywhere ?).
So what do I need to do to make the keyboard disappear when the user is done editing, the "reactive way" ?
Thanks !!!
(Of course right after I post my question...)
It looks like this might actually do the trick :
nameTextField.reactive.controlEvents(UIControlEvents.primaryActionTriggered)
.observeValues { textField in
textField.resignFirstResponder()
}
After fiddling with the different event types, it looks like .primaryActionTriggered is what gets triggered when the "Done" button is pressed.
Any better way to do this ?

Swift: Build succeeds, a blank app window and this message appear: Failed to set (contentViewController) user defined inspected property on (NSWindow)

I tried to create a simple Complex Number Calculator using classes. My application has compiled successfully, but when I ran it, a blank window appeared instead of a window with all my buttons, labels etc. and I got this message in the output window:
2016-03-08 22:20:42.499 Complex Numbers[30404:2328250] Failed to set
(contentViewController) user defined inspected property on (NSWindow):
Cannot create BOOL from object <_NSControllerObjectProxy:
0x6000000022c0> of class _NSControllerObjectProxy
This is my ViewController class code. It involves a complexNumber class, which I didn't submit here:
class ViewController: NSViewController {
#IBOutlet var Screen: NSView!
var a = complexNumber();
#IBOutlet var realValue: NSTextField!
#IBOutlet var imaginaryValue: NSTextField!
#IBOutlet var resultLabel: NSTextField!
#IBAction func lengthResult(sender: AnyObject) {
let r = NSString(string: realValue.stringValue).doubleValue;
let i = NSString(string: imaginaryValue.stringValue).doubleValue;
a = complexNumber(real: r, imaginary: i);
resultLabel.stringValue = String(a.trigonometric());
}
#IBAction func trigonometryResult(sender: AnyObject) {
let r = NSString(string: realValue.stringValue).doubleValue;
let i = NSString(string: imaginaryValue.stringValue).doubleValue;
a = complexNumber(real: r, imaginary: i);
resultLabel.stringValue = String(a.length());
}
#IBAction func operation(sender: AnyObject) {
a = complexNumber(real: NSString(string: realValue.stringValue).doubleValue, imaginary: NSString(string: imaginaryValue.stringValue).doubleValue);
realValue.stringValue = ""
imaginaryValue.stringValue = "";
let b = complexNumber(real: NSString(string: realValue.stringValue).doubleValue, imaginary: NSString(string: imaginaryValue.stringValue).doubleValue)
switch sender.stringValue {
case "+": a = a.sum(b)
case "-": a = a.dif(b)
case "x": a = a.mul(b)
case ":": a = a.div(b)
default: a = a.sum(complexNumber())
}
}
#IBAction func displayResult(sender: AnyObject) {
resultLabel.stringValue = String("\(a.real) + i*\(a.imaginary)");
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override var representedObject: AnyObject? {
didSet {
// Update the view, if already loaded.
}
}
}
I found a similar thread here, but I don't think it's what I was looking for.
Can you help me, please?
Another reason - when you setup wrong binding.
Example of my error:
Failed to set (contentViewController) user defined inspected property on (NSWindow): [<NSProgressIndicator 0x10111b890> valueForUndefinedKey:]: this class is not key value coding-compliant for the key Enabled.
To solve this you need to delete the binding here:
For me was a timing issue I guess. All begins after I added an SFAuthorizationView some days ago, and I discovered that thanks to a bug report, where also was clear that this is happening on older OSes like Sierra, but it is fine, instead, in 10.13+.
Moving some code from viewDidLoad() to viewDidAppear() the problem gone.
Basically I'm just waiting to call any related method of the problematic view later the viewcontroller content view is declared as loaded. Clearly a an Apple problem fixed in new OSes. So after instantiate the nib/xib/storyboard involved I think anyone encounter problems like that should firstly show the view and then customise it. Just my testimony.
I had this problem and figured it out.
In my view I had a user defined property (if you look at the top of your view where you have view controller and first responder you should see it's icon next to it).
Simply delete it and run your application.
Hope this helps!
I you've created an app with a"storyboard" i.e. if there's a storyboard file with your views and windows in it, then there's one of two things missing:
1) If theres a main window and a view that should be it's main view, then right click - drag from the window controller to the view that should be the main view.. When the popup happens, click on "content view" i.e. like follows:
Check out my video example
If this fails, then I'll dig out plan two :)
How this helps!!
Ade.
One thing that may help others, I saw the same message, it looked like the contentViewController was the problem, but it turned out it was another component in something I was writing was failing. It seems the window manager catches all exceptions, not just window exceptions, and prints this deceptive message. What worked for me is stepping through to find component is not loading.
This happens when there is an error or exception in ViewDidLoad.
Ensure that error is cleared and your UI will load fine and u wont get this message.

Changing tintcolor for a specific TabBarItem in Swift

I have 3 TabBarItems in my ViewController
One of them is default when screen loaded. But it is not highlighted
I am trying to highlight it manually
verride func viewDidLoad() {
super.viewDidLoad()
if let items = self.TabBar.items as? [UITabBarItem]? {
let button = items![1]
button.image = button.image?.tabBarImageWithCustomTint(UIColor.redColor())
}
I am getting an error that "Value of type UIImage has no member tabBarImageWithCustomTint"
Any suggestions?
There are two options to set mode for images. Here i am explaining using ImageAssets
Step 1: Add image to ImageAssets.
Step 2: Set the Render As to Template Image from attribute inspector
See screenshot:
And keep the same code which you have done already.
I believe you have to do:
button.image?.tabBarImageWithCustomTint = UIColor.redColor()

How can I disable a button until text in all UITextFields has been entered in swift?

I need a way to disable the save button until text has been entered in all of the required text boxes? I am developing the application in Swift and I have found lots of answers in Objective-c. As I have absolutely now Objective-c knowledge, I am unable to work out what it means.
Does anybody have a solution for this which can be done in Swift?
I know how to enable/disable a button. I also know how to check if a text field is empty. I'm just not sure how to make it so that my code is always checking to see if it is empty or not. I have tried a while loop but as I expected, this froze everything.
Listing one of the ways to achieve this:
class ViewController: UIViewController, UITextFieldDelegate {
#IBOutlet weak var textField: UITextField!
#IBOutlet weak var button: UIButton!
//Need to have the ViewController extend UITextFieldDelegate for using this feature
func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {
// Find out what the text field will be after adding the current edit
let text = (textField.text as NSString).stringByReplacingCharactersInRange(range, withString: string)
if !text.isEmpty{//Checking if the input field is not empty
button.userInteractionEnabled = true //Enabling the button
} else {
button.userInteractionEnabled = false //Disabling the button
}
// Return true so the text field will be changed
return true
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
//Setting the Delegate for the TextField
textField.delegate = self
//Default checking and disabling of the Button
if textField.text.isEmpty{
button.userInteractionEnabled = false // Disabling the button
}
}
}
Reference Link for the above solution
Despite of all the comments given so far and to not blow up the comment area further, I try to give some hints on how to solve your problem:
Put all the textfields in an outlet collection
Set the delegate of all textfields to your viewController
implement the delegate's didEndEditing method and within that method iterate over the outlet collection to check each textfield for its input
Note that this is only ONE way to implement that but you might get the idea.
Use the textfield's delegate methods (or the target-action pattern) to check the conditions required for the user to proceed. If they're met, enable the button.

Resources