setValue not moving UISlider - swift

i have added a slider to my storyboard and connected it. the result is this code inside my "Viewcontroller.swift":
#IBOutlet var control1: UISlider!
when i try to change the value with this command:
control1.setValue(resultAvPitch, animated: false)
the app is crashing:
Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value 2020-02-15 13:55:54.045989+0100 UIGrid[8695:898849] Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value (lldb) –
i found somewhere a small code snippet and put it above this function:
let control1 = UISlider()
like that its not crashing anymore but it doesnt make the slider move.. what am i doing wrong?. is there an option that i need to click somewhere in the storyboard?
note: i placed the slider inside a view and another view like that:

what helped in the end was removing all sliders, drag and connect them again. i have checked muliple times what the differences were but i didnt find anything.

Related

Getting error due to item found nil during unwrapping of Optional Value

I am trying to add a button that allows the user to refresh the tableview and bring them back to the top of the table. I am trying to add a snippet of code that has a var set up like this var layoutGuide:UILayoutGuide! but it is giving me this message. I then try to run the simulator and simply ignore this message but then I get an error saying it has found an optional value nil when unwrapping it. Any ideas on why this is happening? Thank you
Use: let layoutGuide = self.view.safeAreaLayoutGuide instead of var layoutGuide:UILayoutGuide.

How to manually assign an Image to UIImageView

I am trying to add an Image to UIImageView programmatically.
I found a code from here that I've tried a few times but it stopped working for some reason.
popupImage.image=UIImage(named: "juice")
I get this error message:
"Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value"

Forcing update to placeholder complication on Apple Watch

Here a simple issue I am facing while starting to experiment with WatchKit and complications.
I created a simple app which is showing a complication with a public string “Y” and by clicking it, the Apple Watch app is shown with a simple switch.
I wrote my code in getPlaceholderTemplateForComplication in ComplicationController.swift and added a switch IBAction in InterfaceController.swift.
By changing the value of the switch, the public string cycles between “N” and “Y”. I would like to have it changed in the complication as well. However I am noticing that the complication stays as it is initially at “Y”.
I found a similar question about forcing complication updates, but it was related to a TimeLine complication func and not placeHolder.
func updateComplication() {
let complicationServer = CLKComplicationServer.sharedInstance()
for complication in complicationServer.activeComplications {
complicationServer.reloadTimelineForComplication(complication)
}
}
It is not clear to me on where and how to use this in my case.
As suggested I worked on getCurrentTimelineEntryForComplication .
In order to test a ModularComplication only, I used:
switch complication.family {
case .ModularSmall:
let modularSmallTemplate =
CLKComplicationTemplateModularSmallRingText()
modularSmallTemplate.textProvider =
CLKSimpleTextProvider(text: stringa)
modularSmallTemplate.fillFraction = 0.95
modularSmallTemplate.ringStyle = CLKComplicationRingStyle.Closed
let template = CLKComplicationTimelineEntry(
date: NSDate(), complicationTemplate: modularSmallTemplate)
handler(template)
default:
handler(nil)
}
I have the switch IBAction in InterfaceController.swift.
I am encountering issues in using:
func updateComplication() {
let complicationServer = CLKComplicationServer.sharedInstance()
for complication in complicationServer.activeComplications {
complicationServer.reloadTimelineForComplication(complication)
}
}
Where do I have to write the above mentioned func, in order to be able to call it from inside the IBAction?
If I write it in ComplicationController.swift, by calling it from the IBAction in InterfaceController.swift as:
ComplicationController.updateComplication()
I get the error “Missing argument for parameter #1 in call”,
while if I write it in InterfaceController and call it in the IBAction, although the build is successful, when running the App and changing the value of the switch I get the following error: “fatal error: unexpectedly found nil while unwrapping an Optional value” on the line:
for complication in complicationServer.activeComplications
of func updateComplication.
It's not the placeholder text that you want to update. The placeholder template is a static template that's displayed in the selection screen for your complication while you are customizing your watch face. It's only called once to get the placeholder text, and doesn't get called when a timeline is reloaded.
The complication's current (actual, live) timeline entry is provided by getCurrentTimelineEntryForComplication. This function is where you should use your model's on state of the switch to create a CLKTextProvider containing a "N" or "Y" for the active complication family.
Finally, you should call updateComplication() from your switch IBAction to reload your complication timeline, which would update the current entry to show the new state of the switch on the watch face.
Since your complication is updated manually, you should return a nil updateDate in getNextRequestedUpdateDateWithHandler to avoid scheduling your complication for any regular updates.
Update for your edited question:
You should include the updateComplication function in your interface controller, as your complication controller isn't meant to be instantiated by you.
In regard to the "Unexpectedly found nil while unwrapping an Optional value" error, this is an issue that has been mentioned on the Apple Developer Forums.
If you are already running watchOS 2.1, you could try the latest watchOS beta to see if the issue has been fixed yet for 2.2. You should also file a bug report and dupe radar 22947535.

Combobox component for Swift (failed with DownPicker)

I need a component like comboBox when it dropes down and allow user to select value. PickerView looks terrible and one I found nice looking was DownPicker
I followed instructions, installed it and tried to use but I did not see the data I pass to this component in it.
let data = NSMutableArray()
data.addObject("1")
data.addObject("2")
data.addObject("3")
let a = DownPicker(textField: group!, withData: data)
Also nothing happens when I tap down arrow icon
Just advice me another components like this one which will work correctly with xcode 7 beta 6 or help me to fix problems with current try. Thanks)
Update:
I've just tried this one. Nothing good from it too :\
DownPicker is working fine with Swift. I just tried it and use it in my project. The problem I see is that you init DownPicker to local variable. There are two ways how you can use DownPicker in your project and it looks you choose Control Wrapper. So you should have in your controller these controls:
#IBOutlet weak var personTextField: UITextField!
var personDownPicker: DownPicker!
The first one is outlet connected to UITextField added in storyboard. DownPicker I Initialized in viewDidLoad:
override func viewDidLoad() {
super.viewDidLoad()
let persons: NSMutableArray = ["Architect", "Designer"]
self.personDownPicker = DownPicker(textField: self.personTextField, withData:persons)
}

WKinterfacePicker item issue

I have a WKInterfacePicker in my Watch's Interface and want to add items to it. Here is my code I currently have:
let item1:WKPickerItem = WKPickerItem()
item1.title = "1"
let item2:WKPickerItem = WKPickerItem()
item2.title = "2"
timePicker.setItems([item1, item2])
When I run the app it crashes and tells me there is a nil last line:
fatal error: unexpectedly found nil while unwrapping an optional value
I had a look at Apple's docs for the WKInterfacePicker and WKPickerItem but that did not help me either. Is it possible that I have to set the content of the items somehow else? I thought the title is the content already and I couldn't find any other method for setting content.
It's likely that timePicker is nil. Did you remember to hook it up to the outlet?
#IBOutlet var timePicker: WKInterfacePicker!
Since it's declared with !, this is the only place you could be force unwrapping nil.
If you're still having problems, there's a full guide on WKInterfacePicker you can try here: http://www.sneakycrab.com/blog/2015/6/12/wkinterfacepicker-in-watchkit-20-using-the-digital-crown