When segue is performing throws unrecognized selector sent to instance error message showed? - ios7

I've been looking for a solution since yesterday, and i still can't figure out actual problem.
My app has been worked for 2 months on ios8 devices. I also set it up for ios7 devices, but I didn't know it was crashing on ios7 devices because of segue.
This is prepareSegue function:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?)
{
if (segue.identifier == "navigateToSettingsView") {
if let settingsView = segue.destinationViewController as? SettingControllerView
{
settingsView.isSetup = self.isSetup
}
}
}
My segue style is present modally and current context.
I have navigate function to perform segue like this:
func navigateToSettings() {
// call setting view for adjusting settings
dispatch_async(dispatch_get_main_queue(), {
self.performSegueWithIdentifier("navigateToSettingsView", sender: self)
})
}
I'm still tracing debug now, it's getting me annoyed so much. And in the debugger log area. The only prompt is 'containsString:' and unrecognized selector sent to instance. I know unrecognized selector issue, sorry for that. But my problem has no reason on debug log.Also, i can't use allocations instruments because of ios7.Eventhough, I'm not using any String contains function. I know the issue rangeOfString :S
[__NSCFString containsString:]: unrecognized selector sent to instance

I just ran into this issue as well, however my problem is in iOS 6.1 so it may be different. I didn't try to re-produce the issue in iOS 7 yet.
What I discovered was a newly added UITextField on my storyboard caused the crash. Removing the UITextField fixed the problem.
You may want to remove some recent UI elements from your storyboard and see if that helps. I found copying an existing UITextField and pasting it where I wanted the new one still allowed my app to run on iOS 6.1.

Related

Set custom navigation bar class in UINavigationController

I have a custom navigationBar :
class Name_UINavigationBar: UINavigationBar {
// code
}
and I want to set it to my navigation controller programmatically. So I tried :
var navController : UINavigationController = UINavigationController(
navigationBarClass: object_getClass(Name_UINavigationBar),
toolbarClass: nil)
// code
But it crash saying :
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: 'MyProject.Name_UINavigationBar is not a subclass of UINavigationBar'
Try this.
let navController = UINavigationController(navigationBarClass: YourNavigationBar.self, toolbarClass: nil)
I encountered the same error and was able to get it working again like that.
In Swift there is no supported way to get the Class of an object. You're problem is almost certainly to do with the object_getClass method which I believe is no longer supported as of Beta 5.
I imagine APIs like this will either be updated, rewritten or simply deprecated soon. For now you will need to do it in Objective-C.

Prepare for segue not working with swift

I using a tableView inside a viewController. I am trying to send data to a detailViewController. But for some reason i can't push to the detail view. I am not getting any errors. Its just not working.
Here is my code for the segue:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject) {
if (segue.identifier == "test") {
let detailViewController: DetailViewController = segue.destinationViewController as DetailViewController
//println(index)
detailViewController.fromPreviousView = index
//
}
You registering tableView cell programatically , So it will create different cell not the one in the storyboard so there is no segue.
Solution is delete this line of code self.tableViewOutlet.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell") and give cell identifier to the cell in story board to "cell". It will work.
It seems that is a bug from the last beta (4 maybe till the beta 3) release of Xcode 6. I'm facing the same problem till I have upgraded to this new version. The "prepareForSegue" method is never called. The same code worked with the previous (beta 2) release but I didn't see anything about that in the "Known issues in Xcode 6 beta 4!" section in the release notes but there is a list of IB issues.
Check the source code for storyboard by right clicking MyStoryBoard->Open As->Source Code.
Search for :
trigger="accessoryAction"
If you find it , delete it.
Sometime ctrl+dragging adds this additional attribute causing issues with prepareForSegue.

iOS: More tab crashes on my subclassed UITabBarController on iOS 7.1

I simply updated to iOS 7.1 and I get an unrecognized selection error for a function called "_layoutCells".
I have a simple subclass of UITabBarController.
Note that this is a hack to avoid a bad crash until a better solution or explanation is found. I though I should share it.
Simply add the following method to your UITabBarController subclass implementation:
- (void) _layoutCells
{
// HACK ALERT: on iOS 7.1, this method will be called from deep within the bowels of iOS. The problem is that
// the method is not implemented and it results in an unrecognized selected crash. So we implement it...
//
// What could go wrong?
}
Thanks to GenesisST for giving his answer, but I know methods are called for a reason. And usually layoutCells will call layout for all subviews. While I rather wait for an answer from Apple, I like other people need to submit my app within a given timeline.
In my case, I was getting this error due to some hacks. I had replaced the UIMoreNavigationController delegate, which is an undocumented class by Apple, so I could expect errors. I am doing this hack to extend the More tab's functionality, and this error only occurs when I change the moreNavigationController tableView's delegate.
So I store their delegate, change it, then call _layoutCells to their delegate when iOS calls it on my class.
- (void)_layoutCells
{
if([self.moreTableViewDelegate respondsToSelector:#selector(_layoutCells)]){
[self.moreTableViewDelegate performSelector:#selector(_layoutCells)];
}
}
I don't know if this apply's to anyone here, but just in case someone else comes to SO with my edge case.
I've had the same issue in my app where I have provided custom delegate/datasource to the more tableview controller. I haven't figured out why, but it seems that _layoutCells method is invoked on the more tableview controller.
I fixed it, adding this method:
-(NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector
{
// self.viewController is my tabBarController
UINavigationController* moreNavigationController = self.viewController.moreNavigationController;
// Retrieve the more list controller (it is the first in the hierarchy)
id moreListController = moreNavigationController.viewControllers.firstObject;
Class moreTableViewClass = [moreListController class];
if (moreTableViewClass) {
return [moreTableViewClass instanceMethodSignatureForSelector:aSelector];
}
return nil;
}
I've done various test and it seems a reliable workaround. But if you'll find better solution... share it!

Perform segue from unbutton results in "unrecognized selector" error

I have implemented a simple segue from a button click. Here is the view controller code:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
{
if (self.categoryInt == 1)
[segue.destinationViewController setCategoryKey:SD_ADDITION];
else if (self.categoryInt == 2)
[segue.destinationViewController setCategoryKey:SD_SUBTRACTION];
}}
- (IBAction)category1Selected:(id)sender {
self.categoryInt = 1;
[self performSegueWithIdentifier:#"ShowWorksheet" sender:self];}
From the log messages, I can see that it ran through the ViewDidLoad on the destinationviewcontroller completely but then it errors out
with: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MainMenuViewController categorySelected:]: unrecognized selector sent to instance 0x75360e0'
I have not implemented any specific selectors on these buttons. Also there is no "categorySelected" method in my MainMenuViewController. The method being invoked is "category1Selected". What is causing this error?
I think you answered the question yourself. You are somehow sending "categorySelected" when you SHOULD be sending category1Selected.
Check to see if you previously wired a button to categorySelected in interface builder. If you had previously done this, but then changed the name of categorySelected to category1Selected in your code, interface builder would probably not update.
This is usually a connection error, go to your connections inspector and make sure all is correct there.
If your not sure disconnect all the connections and re make the connections double checking everything.
Also Make sure you haven't connected the action button as an outlet in addition to its action command.

Can I have a block of code run only if user is on iPhone vs iPad?

I have a master-detail app that is working great for the iPad. However, the iPhone version doesn't work because a variable that is being sent to the DetailViewController in the iPad version doesn't send to the iPhone DetailViewController. I can fix this with a single line of code in MasterViewController implementation:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
self.detailViewController=segue.destinationViewController;
}
Unfortunately, when I implement that code, the iPad version stops working. I get an exception when I go from another view controller (HomeViewController) back to DetailViewController. That error log is:
2012-07-14 14:29:12.924 46 Tracker[2772:11603] -[HomeViewController setDetailItem:]: unrecognized selector sent to instance 0x7cad4f0
2012-07-14 14:29:12.925 46 Tracker[2772:11603] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[HomeViewController setDetailItem:]: unrecognized selector sent to instance 0x7cad4f0'
*** First throw call stack:
(0x148a022 0x201acd6 0x148bcbd 0x13f0ed0 0x13f0cb2 0x2cb0 0x2d75c5 0x2d77fa 0xb6c85d 0x145e936 0x145e3d7 0x13c1790 0x13c0d84 0x13c0c9b 0x16a07d8 0x16a088a 0x246626 0x1fdd 0x1f45)
terminate called throwing an exception(lldb)
So, is there any way I can run that first block of code only when the user is on the iPhone? Or, can I fix the code to make it work properly on both devices?
Here is a link to my iPad storyboard to (hopefully) make it more clear. I have a problem when I click on a table cell AFTER going from HomeViewController back to DetailViewController: http://www.grapekeeper.com/storyboards.png
Perhaps the following?
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// perform iPad logic
} else {
// perform iPhone logic
}