Getting 'NSInvalidArgumentException' error while using 'endEditing' - ios

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.

Related

App Termination when button clicked swift

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.

[Controller _mutableLayoutArrangements]: unrecognized selector sent to instance

I just converted a objective c class to swift 4 and while i'm running the code on the outlet property of button app is crashing
#IBOutlet var btnSelected: UIButton!
crashed at btnSelected.isHidden = true
[Controllet _mutableLayoutArrangements]: unrecognized selector sent to instance
I tried removing and re connecting the outlets but issue didnt resolve and this issue is coming with every outlet
outlet is connected
goto storyboard and right-click on the btnSelected and check whether the btnSelected is having only one outlet, Also if you can attach a screenshot please do.
Change the code with below code for button Outlet
var btnSelected: UIButton?
And then go to Storyboard > remove the connection with button and reconnect it to btnSelected IBOutlet

"unrecognized selector" error with bridging header even it's added in settings

I added the .h and .m files of this project and created a bridging header. I made sure that the bridging header location is entered correctly in project settings...
...and it imports the required file.
I have an UIView in my ViewController and its type is set to IPDFCameraViewController. In viewDidLoad() I'm calling a function in this class:
#IBOutlet weak var cameraViewController: IPDFCameraViewController!
override func viewDidLoad() {
super.viewDidLoad()
self.cameraViewController.setupCameraView()
self.cameraViewController.isBorderDetectionEnabled = true
}
I have no errors or warnings, but when it tries to execute cameraViewController.setupCameraView() it crashes and throws following:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView setupCameraView]: unrecognized selector sent to instance 0x7ff1b0930620'
I'm probably missing something so simple but this is driving me crazy, what should I do?
You haven’t set the custom class for your view in the storyboard, so your outlet is referring to an instance of UIView, and of course UIView doesn’t have a function setupCameraView.
Error because you set UIView of type UIViewController. View controllers has to be added as childViiewControllers not through uiviews. In your storyboard add ContainerViewController, set it to your IPDFViewController and then make outlet

Click on custom back button from detail page to previous tableview is crashing app (in only iOS8)

I have a app with following structure
first i have a button in my home page when i click that it will open a new UITableView and display list of "Main Programs" When a user click on any of those will open another view controller and display all "Sub Programs" in that user can select each sub programs to see the details.
All these are working fine till iOS 7 versions. Recently i upgraded device to iOS 8 (iPad and iPhone) then i run the same code and when we return from "Sub Program Detail " page to "Sub Program" Page App is crashing. There is no log message .Only am getting this one
Please help ,The back button is working fine but something in that previous tableview controller not working .
i tried to do instrumentation then i got following message http://postimg.org/image/ytezux0m9/
Then i tried to debug it but i couldnt find anything wrong there (every value was correct) and then i tried to add "tableview relaod data" to ViewWillAppear () .And then i got a crash log like this
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UISearchDisplayController numberOfSectionsInTableView:]: unrecognized selector sent to instance 0x124e6e7a0'
*** First throw call stack:
(0x1872ee084 0x1978d40e4 0x1872f5094 0x1872f1e48 0x1871f708c 0x18be51d38 0x18bb49480 0x18bb491f4 0x18bb4fe74 0x18ba6d140 0x18ba8e4c8 0x18ba6ce58 0x18ba6ce58 0x18ba8e4c8 0x18ba6ce58 0x18ba6ce58 0x18ba6ce58 0x18ba6c528 0x18ba6c408 0x18ba77ea4 0x18bc5ab18 0x18ba7e77c 0x18bc5a3a4 0x18bc14278 0x18bb24f40 0x18bb24d0c 0x18bb24c8c 0x18ba6d874 0x18b3c5d58 0x18b3c0944 0x18b3c07e8 0x18b3bffe8 0x18b3bfd6c 0x18ba6f790 0x1872a6324 0x1872a55c8 0x1872a3678 0x1871d1664 0x1903135a4 0x18bad64f8 0x1000a4c80 0x197f42a08)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Just now i run then i got this in my log
-[UITextFieldLabel numberOfSectionsInTableView:]: unrecognized selector sent to instance 0x12fe79f70
UPDATES :
one more thing like when i going forward my if condition is true and when i click back button its geting false and execute else part for - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section method code is here http://postimg.org/image/kikrbltj1/
I think the reason for the crash is that when you click on the back button from detail, popViewController is called twice. The navigation controller firstly pops the "Sub Program Detail" page, and then immediately pops the "Sub Program" Page. In the "Sub Program" viewWillAppear method, a setupContainer method is executed and loading some FKRSearchBarTableViewController which has table to be filled.
So when the navigation controller firstly pop the "Sub Program Detail" Page, app goes to the "Sub Program" page's viewWillAppear method, where setupContainer is executed and tables are loading data, at the same time, "Sub Program" page is poped out."Sub Program" is dealloc'ed, So are the FKRSearchBarTableViewControllers, which are busy loading their tableViews. That's why message sent to dealloc'ed object.
You can move the line [self setupContainer] in DAViewController from viewWillAppear to the end of viewDidLoad, and remove the lines
if ([self.navigationController.viewControllers indexOfObject:self]==NSNotFound) {
// Navigation button was pressed. Do some stuff
[self.navigationController popViewControllerAnimated:YES];
}
from viewWillDisappear in THProgramDetailsViewController.m.
Since in backBtnClick method, pop action has already been executed.

performSegueWithIdentifier: causes app to crash

I have a button that is pressed after user enters email information. I have an alert view that is displayed when there is no email entered but if there is I want the button to segue to another view controller.
The following code causes my app to crash. I have no idea why. Please help.
(note: I have tried "sender:self]" "sender:nil]" and "sender:sender]" and they all make my app crash.)
- (IBAction)nextButtonPushed:(id)sender {
if ([self.emailTextField.text isEqual: #""]) {
emailAlertView = [[UIAlertView alloc] initWithTitle:#"Missing Email" message:#"A destination email is required to send." delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[emailAlertView show];
self.nextButton.enabled = NO;
}
else {
eString = self.eTextField.text;
hString = self.hField.text;
emailAddress = self.emailTextField.text;
[userDefaults setObject:eString forKey:#"e"];
[userDefaults setObject:hString forKey:#"h"];
[userDefaults setObject:emailAddress forKey:#"email"];
[self performSegueWithIdentifier:#"next" sender:self];
}
}
There are three overwhelmingly likely possibilities:
Perhaps the storyboard really has no segue named "next" emerging from the FirstViewController scene. Be careful: spaces and capitalization and things like that matter.
Perhaps the storyboard has a segue named "next" but it emerges from a different scene (a different view controller).
Perhaps the FirstViewController instance represented by self in your code is not the same as the FirstViewController instance in the storyboard, i.e. maybe it came into existence in some other way and not by instantiation from the storyboard. You might even have two FirstViewController objects in the storyboard, and the segue comes from the other one.
One great way to figure out why your app is crashing on a line like this is to disable any breakpoints you may have (including exception breakpoints). This will cause the app to crash and often tell you a reason why it is crashing. Normally you'll get error's like #matt mentioned such as bad identifiers on your seques (often typing errors), multiple of the same object in an IB scene such as the following:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<YOURAPP.YOURVIEWCONTROLLER: 0x7c8951d0>) has no segue with identifier 'TheSequeIdentifierYouHaventSetYetOrTypedInWrong''
or like in my case today where I got this error:
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<YOURAPP.YOURVIEWCONTROLLERYOUARETRYINGTOSHOW 0x78e5a140> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key "MyKeyOnTheOffendingObject"
Once I knew that I had an object in my storyboard with a key that it should not have all I had to do was track down the Button/Image/Other Random Object with the bad Referencing Outlet or Sent Event and all was fixed
Often performSequeWithIdentifier will come up as the last line shown before a crash since that is the last line that worked before a problem was found when presenting a new View Controller - so if you are sure the problem isn't with your seque then check references on the VC you are trying to present!
Crashing can also occur if the view controller cannot load from the NIB. For example if there is an incorrectly named User Defined Runtime Attribute.
For example QBFlatButton changed their API today and my app started crashing. This is why we use semantic versioning :-)

Resources