Console won't print, only "...unrecognized selector sent to instance 0x####XX0" Runtime Errors - iphone

I'm working on an iPhone app (first real programming project) and I had two views that would go into tabs in separate applications to build them, where they work fine. Then I added them back into the main project; The tableviews bring on a crash with an numberOfRowsInSection] unrecognized selector sent to instance 0xXXXXXX so I isolated the other view to fix any errors there first. I'm using xibs.
But on the other view, when I click a Button that triggers a custom method, I get an *** -[UIViewController methodName]: unrecognized selector sent to instance 0x####XX0 just like the last one.
What also puzzles me is that the console won't print anything else except these errors; I have NSLogs() all over the place and they're not showing up, even in the appDelegate. They do however show up when they're in the main. (Because of the application life-cycle right?: then the error gets there first and I don't see my NSLogs)
The unrecognized selector messages are logged because of methods. I have all my synthesize statements and have searched questions here, but they're not like mine (I think.)

When you say you added the XIB files "back into the main project" it makes me think this is the likely area of concern.
I think it may be the case that these XIB files are still thinking they are classes in the old application (where you originally built them). I suggest:
Opening up each XIB file and removing all the connections
Then check the class name of the "file's owner" and check that this is the class in your new application. If the class names are the same in the old app as the new, change to something else and then back again.
Hopefully this will sort it. If it doesn't, try creating a brand new XIB file and then building it in the same way as you built the others. If this still doesn't work the problem is in the class; if you let us know then we can come back with further ideas in this area.
Hope that helps!

I've since removed the second view from it's xib and instead put it in the main xib, with an added UIViewController object that has it's class set to my subclass. Now it's working, and I'm moving on to the next part. I think it was that I left out UIViewController in one way or another from the xibs
As stated above, almost everything being worked out now. Thanks though and silly me for posting such a question.

Related

How to check which class/UIViewController is executing while testing on device on Xcode?

Recently I have been working on an old swift project built in back in 2015. Its really difficult to find which ViewController is executing currently because of the naming convention, usage of really massive storyboard(I feel terrified to even go to the main.storyboard) and various reason like usage of different language. Of course I can find it but it takes long. I was thinking if there is any way like when I run the project on a device and navigate to different page is there any way to see in the console which ViewController is executing ?
There is a quick way to find what view controller you are on when you are running your app.
1) Launch your app on the device or simulator.
2) Go into Xcode and tap this button:
3) This will open the Debug View Hierarchy. Click on the phone and you will see all the elements in the top bar. You can also see a hierarchy on the left-hand side. In here, you can click down and you will see the name of the view controller on screen.
Using the debugger after putting a breakpoint where you prefer you can write this and press return.
Swift 4.x
po UIApplication.shared.keyWindow?.rootViewController?.value(forKey: "_printHierarchy")
This method is a private API, thus you cannot use on production code, just use it in debug or from the debugger console.
I think it is better to see in debug area for your current viewcontroller named self, you get all information from there open the dropdown and and see you need to put break point in your viewController init method or where you want to debug, However you want to know programatically which is you current viewController you can get it by
appDelegate.window.currentViewController()
If you need which ViewController is Pushed or presented you can get from the above code but the case will be different if you are using the Slidemenu controller, I mean it is totally depends on how you have started navigation and which navigation controller is currently is use.
Can you briefly describe why you need current ViewController so i can help you further.

Swift ViewController does not respond to -getFile, Could not connect action, target class

My code works all fine but there is always two console message every time I run it.
app works fine but the messages just bugs me so much. Could anyone tell me what is wrong with my code and what does these console message means,thanks
2016-06-13 14:31:15.014
LazyHackintoshGenerator[1625:37250] Could not connect action, target class
LazyHackintoshGenerator.ViewController does not respond to -getFile:
Select your ViewController.
Right-click on its “View Controller” icon (the blue circle with a white square inside).
Look for warning icons (yellow triangles).
Hover over them. An explanation of the problem will appear.
As Feldur said, the problem is probably a leftover link from your storyboard to a method that does not exist anymore (maybe you renamed it or deleted it manually). Remove the link by clicking on the cross, and, if needed, re-link to the appropriate method in your code.
Here is an example of what it will look like in Interface Builder.
Likely a control's action in your storyboard is linked to a method getfile that no longer exists

Unknown class in Interface Builder file

Why am I still getting this error when I run my iPhone app? The file is a ViewController that I have been working to delete and replace, but it just won't die. As far as I know, I don't have any reference (string or otherwise) to this file in my project.
I have deleted the related file (I'm trying to get rid of it.)
I have cleaned the project and rebuilt.
I have "Reset Content and Settings" in my simulator.
I have done a grep (grep -i -r "TheClassName" *) and nothing matches except my UserInterfaceState.xcuserstate file.
I have searched the code using XCode's Find/Replace tab.
I have double checked my Build Phases and am pretty sure it isn't in there (its a large project).
Any other ideas? I've spent way too many hours trying to figure this simple thing out; I must be missing something.
Thanks!
Check your nibs or storyboard, and make sure none of your views are set to the class!
I finally fixed the problem after trying it on multiple machines over the course of almost 2 days! I will not be thwarted!
I tracked the problem down to a call to setViewControllers on a UINavigationController which is called on initialization of the application. I was always being passed 3 objects (there are 3 panes in the navigation controller). Even though I had deleted the third object, as previously explained, three objects would always be passed in. The class type of the first two was correct, but the third would just be a UIViewController. Curiously, this view controller had a nibName which corresponded to the object file and Xib file that I had previously deleted. Of course, when view was called on this borked UIViewController, it would crash since the corresponding nib had obviously been deleted. Remember, the textual name of this object or Xib could not be found in my directory with grep, so I have absolutely no idea how in the world it came into existence when I ran my app.
So, I figured the app may not have been cleaned properly. I double and triple checked this. I even validated that my Workspace settings were correct (File->Project Settings->Advanced). The app was indeed being recompiled fresh every time.
Secondly, I started thinking that perhaps the object was being set by some other means. Working backwards, I added some breakpoints and found out that initWithCoder was being called on the parent UINavigationController--this was eventually working down to call the setViewControllers on the object and assigning the three view controllers (one of which was the offending one). I could easily see from the call stack that the Nib file that was being loaded was deserializing something offensive.
So, I started digging into my Xib file. Of course, the object name wasn't in the file (as expected since the grep didn't find anything). I deleted and recreated the portion of the Xib that included my root UINavigationController. This ended up changing the Object ID and ref within the Xib file.
Secondly, I created a new Xib and UIViewController with the same names as the one which I had previously deleted, hoping that Xcode might be happy if I created and then re-deleted them. I then compiled, re-deleted them, updated by Xib file yet again, reverified with grep that yes, indeed, nothing existed with that name.
And it worked. After spending multiple days on this issues, I'm fairly sure that there is a bug here in the interface builder, but do I want to revisit this problem to file a bug report? Absolutely not...
In my case, I solved an issue by name of Custom class name of View instead of Custom class of ViewController. By mistake i added like this for view as shown below.
It Should be for ViewController like this.
This is in my case, for you may be it's related with another component.
This happens when the view class is in a framework. Select the framework's module. Example with a CocoaPod: HSegmentControl.
Make sure when you add or rename or move files around especially in folders, that when you add them you:
A. Create Groups, not references they don't usually read in.
B. Check the boxes for the apporpriate "Product(s) or Target(s)" you want to add the source to.
Another thing to try :
I had to toggle "Inherit from Target" under the "Module" control of "Custom Class."

IBAction Button “Unrecognized Selector Sent to Instance” Error

I spent a while searching for the answer for this question on google and managed to stumble across the answer myself and thought I would share it.
I was getting the “Unrecognized Selector Sent to Instance” Error. I traced it to my button.
What I had done with out realising is assigned two methods to a button. I had made a method and linked it to the button. I then deleted that method made another one and linked it to the button. I didnt realise that the button was still linked and looking to run the old method that was no longer there.
Just go to you xib, select button and then in connectionInspector (cmd + option + 6) delete your previous connection.
To solve this is quite easy. Go on the your storyboard and right click on the button. It will display a list that shows what method it is linked to. If there is more that one there delete all the others that you dont want. This should get rid of that message.
Another thing to note was I was getting a warning that my method had incomplete implementation. I didnt know why that was at the time but it was because there where button methods that werent being implemented.
I got caught by the same problem, and realised that:
If you delete a function, the links to it in the Interface Builder is still there, you have to manually delete them, or they will link to the non-exist function and raise a runtime error.
I just deleted the connection between the button in the main storyboard and the view controller. Then I connected the IBAction-code-snippet to the button instead. That worked.

iPhone App Crashes on button click

I made my project in storyboard in, due to issue with the custom UITableViewCell I have made a new project, copied all of the data to my new classes and copied my buttons, images etc from the storyboard views to new project's nib/xib files.
Now When I click on any button my app crashes without any error and it opens delegate file and highlights this line of code
return UIApplicationMain(argc, argv, nil, NSStringFromClass([ThisOrThatAppDelegate class]));
I have already made connections for the required actions from IB to controller. Also I have tried Command+Shift+K for clean code. But the problem is still there.
You have to find out first what the problem is:
use the Debug build config and are using lldb or gdb
make sure you have a breakpoint on all exceptions
make sure you have the "Breakpoints" button top left enabled.
run the app
You should break into the debugger. You need to get to a point where the debugger catches the exception.
Then edit your question and tell us what exception you get. I'm going to guess you'll be getting a objc_msgSend() error, which means that some object is trying to message a non-existent or dealloced object. If that turns out to be true, then you can enable "Zombies" (which lets all objects stay around) and see if one of those gets messaged.
If nothing seems to help, then what you need to do is start adding NSLog messages to track your app as it comes up (or use breakpoints, your choice). This takes a long time so you might work backwards - see if your appDelegate application:didFinishLaunchingWithOptions: gets called, and also if you get to the end of it.
Unforunately this type of problem can be take a lot of time to track down. Some object has probably queued a message up for another object on the main queue, so when you get the crash you don't get to see who did what when.
Also, with objc_msgSend problems, when the debugger stops you cannot easily see what object was messaged - but if you turn off the debugger and let the app actually crash, you can find the crash report in the Console app and get more info from that.