App Termination when button clicked swift - ios

When I click a button it triggers this function
#IBAction func groupSquare1Tapped(_ sender: Any) {
userDefaults.set(userDefaults.array(forKey: "groupNames")![0], forKey: "currentGroup")
openMessages()
}
I get the error:
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<Nebula.MessagingViewController 0x15d00ed70> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key scroll.'
It used to work fine but I do now know what is changing.
The openMessages() function just changes the view. When I run the userDefaults line out of the function it works fine so it is not that.
How can I fix this?

When you get an NSUnknownKeyException crash, it is often because you have an IBAction defined in your Storyboard (or XIB file) linked to a view controller that does not implement the method named in the IBAction. In this case, it sounds like the action is "scroll".
Try opening the connection inspector in Interface Builder, selecting the button in question, and clicking the X(es) to delete all the IBActions on that button. Then control-drag from the button to your IBAction method to re-establish the link.

Related

Getting 'NSInvalidArgumentException' error while using 'endEditing'

I'm getting this error:
[Clima.WeatherViewController searchPressed:]: unrecognized selector sent to instance 0x7f996b204020
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Clima.WeatherViewController searchPressed:]: unrecognized selector sent to instance 0x7f996b204020'
Here is my code:
IBOutlet weak var searchField: UITextField!
IBAction func searchedButtonPressed(_ sender: UIButton) {
searchField.endEditing(true);
print(searchField.text!)
}
You just have to disconnect you IBAction of your button & reconnect it. Because it seems that you had changed your IBAction function name after connect it. So your story board still has connection with old name search Pressed. & You already renamed it into searchedButtonPressed so your story board can not find this new name.
For disconnect your IBAction method:
right click on search button in story board & you will see connections you made in manu, close the connection with little colse button placed on top of the corner with the name searchPressed.
For reconnect your IBAction method:
Ctrl press on the keyboard & dreg on the search button to the small circle you will see beside your IBAction method.

App crashes when I add Charts UIView as IBOutlet to ViewController

I am using Daniel Gindi's Charts library.
I have a ViewController in my app that is a scrollview, and it is supposed to display 4 line charts on different axes (i.e they are in different UIViews), and because the lineCharts themselves are quite big, I put them in a ScrollView to ensure that the graphs can be seen clearly.
Before connecting the UIView to the ViewController, the app works fine. I could scroll the page as expected, and also the LineChartView looks fine, it just displays "No Data to Show"
However, I realised my app crashes after trying to debug my failing ViewController. I realised I could not even add the IBOutlet for the LineChartViews into my ViewController. I tried it with one and it gives an NSUnknownKeyException, and the problematic part of the code is the IBOutlet. I have made sure all my connections are clean, in fact I rebuilt the storyboard to make sure everything was fine and it still crashes when I establish an IBOutlet.
There isn't much code involved as it just involves establishing an IBOutlet with the relevant ViewController. I saw in another post that adding chart.translatesAutoresizingMaskIntoConstraints = false might help and it did not.
The error is:
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key chiller1Trend.'
You cannot use chiller1trend as anIBOutlet and as a Cocoa binding key. You need to do one thing or the other, not both, because if you use bindings you don’t need that outlet. Thus, either remove that outlet from the view controller class code or select the UIControl to which chiller1trend is bound in the bindings inspector in your storyboard or xib file and delete that Cocoa binding. Do not forget to check if the module of your controller is also well set.

Getting 'NSUnknownKeyException' after deleting a control and the corresponding outlet in the code

I am writing a very simple app with just one view controller. However I am getting an exception:
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key
Here is what I did:
added a UIImageView and created an outlet in the code by ctrl-dragging to the assistant editor.
deleted the UIImageView cause I don't need
deleted the outlet property from the code
checked the connection inspector and removed the outlet from the storyboard/InterfaceBuilder.
But I am still getting the exception as listed above, could anyone give me some hints?
Usually you should do a clean of your project, found in the Project menu next to build That way xib files get recreated and often such errors disappear.

Xcode Can't remove UIBarbuttonItem without getting error

So i started with my app with 2 buttons in my calenderview : a day and a week button.
Now i want to just use 1 button and dynamically change the name of it (that part works)
I am using the weekbutton for that. But now I want to remove the day button.
But i cant get it out of my program.
I tried first deleting the link in .xib
Then i delete the button.
Then i remove it from the .h file, and then from .m
It always results in the same error :
* Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key dayButton.'
Cant see why i just cant remove the button...
You`ve deleted outlet from code .h/.m file, but somewhere in .xib something is still connected to deleted outlet. Recheck all connections in .xib file to be sure that they have appropriate declaration in .h file.

How to fix error [<UIViewController 0x752f5a0> setValue:forUndefinedKey:]

I'm new to IOS and I'm stuck with an error I added a table view in my storyboard named timelinetable and after some time I deleted that from my storyboard but after that when debugging it shows an error
Terminating app due to uncaught exception 'NSUnknownKeyException',
reason: '[ setValue:forUndefinedKey:]:
this class is not key value coding-compliant for the key
timelineTable.'
but I cant find anything named timelinetable in my project so how can I fix that problem
Go to the xib
click on files owner and click on the show connection inspector button (last one ).
Check out all the connections . The problem is due to you are referencing the outlet which is no more exist.
you connect an outlet and you then remove the controller without removing its outlet.

Resources