iOS copyWithZone unrecognized selector only when using device - ipad

I'm working on an iPad app that launches an initial screen only when there is certain data in a sqlite DB, something like this:
if ((int)[MyStore sharedInstance].mode < 0)
{
self.connectionSettingsViewController = [[[ConnectionSettingsViewController alloc] initWithNibName:#"ConnectionSettingsModalViewController" bundle:nil] autorelease];
self.connectionSettingsViewController.view.transform = CGAffineTransformMakeRotation(M_PI_2);
self.connectionSettingsViewController.delegate = self;
self.launchScreen = [[[UIView alloc] initWithFrame:CGRectMake(-256, 0, 1024, 768)] autorelease];
[self.launchScreen addSubview:self.connectionSettingsViewController.view];
[self.window addSubview:self.launchScreen];
}
That code is in the app delegate. The problem I'm facing is that this works fine in iOS Simulator, but when I try to run on iPad I get the following error:
[someViewController copyWithZone:] unrecognized selector sent to instance.

UIViewController doesn't implement the NSCopying protocol. Unless you've implemented NSCopying in your own UIViewController subclass, your view controller won't respond to -copyWithZone:.

Related

Crash in self.view after constructor on iOS 8.1 and 8.2

I'm trying to do a simple SpriteKit action - adding a view to a scene:
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"LevelsEditorStoryboard" bundle:[NSBundle mainBundle]];
self.levelsEditor = [mainStoryboard instantiateViewControllerWithIdentifier:#"LevelsEditorId"];
[self.scene.view addSubview:self.levelsEditor.view];
On iOS 8.0 and 8.3 is working fine and on iOS 8.1 and 8.2 I'm getting the following error:
SPBingo[75304:80943666] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITextSelectionView name]: unrecognized selector sent to instance
I realised that this crash caused by the UITextField.
Once I'm getting rid of it, replacing the UITextField with some UITextView ( not ideal but whatever) The view is loading but when I try to click on a UITextView it crashed. The other Input views work (switches, dataPicker, tableView etc.)
After a deep dive into it I figured out that the problem occur in the contractor already. When I put breakpoint on the the second line in the following code :
-(instancetype) initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if(self)
{
}
return self;
}
and try to print "self.view" I'm getting the following error:
error: Execution was interrupted, reason: internal ObjC exception breakpoint(-3)..
The process has been returned to the state before expression evaluation.
ODD!
You cannot access the view until after the "viewDidLoad:" method signature is called, otherwise it attempts to create the view before all the prerequisites are in place.
Make sure to call self.view from "viewDidLoad:", "viewWillAppear:" or "viewDidAppear:" when it has properly been setup.
So.. it is an internal bug by Apple which create in 8.1 and fixed in 8.3.
The solution is avoid using the UITextView contractor "initWithFrame" and use the following one:
UITextView *textView = [[UITextView alloc] initWithFrame: frame textContainer: textContainer];

In iOS, how to present a UIViewController and then wait for its return?

In iOS, how to present a UIViewController and then wait for its return?
I want to use Objective-C, not Swift.
For example, I want to realize something like the following:
CustomViewController *myDialog;
NSString *dialogReturn;
myDialog = [[CustomViewController alloc] init];
dialogReturn = [myDialog show];

ios application crashed with "message send to deallocated instance"

My app crashed and the code is the following:
else if(...)
{
CGDetailView *detailView = [[CGDetailView alloc] init];
ContactGroup *contactGroup = [[ContactGroup alloc] init];
[contactGroup setObjectStatus:NewObject];
[detailView setContactGroup:contactGroup];
[detailView newContactGroup:YES];
[contactGroup release];
UIBarButtonItem *temporaryItem=[[UIBarButtonItem alloc] init];
temporaryItem.title = NSLocalizedString(#"back", #"");
self.navigationItem.backBarButtonItem = temporaryItem;
[temporaryItem release];
[[self navigationController] pushViewController:detailView animated:YES];
[detailView release];
}
The error is "message sent to deallocated instance" and it regards the object of type
CGDetailView. I use the alloc-init-release pattern, and I don't really understand why the
app crashed. It usually works.
iOS 7.1 and device is iPhone5 if that helps.
Just try to get the point where your memory is released for this CGDetailView's object and you still calling a method on that object.
You can do it by enabling Zombie Object from edit scheme, it will tell you the point where your app is crashing.

no visible interface declares the selector 'setDelegate'

I have a frustrating problem. I can't wrap my head around the "delegate thing".
My problem is that i can't set a Viewcontroller as the delegate.
-(IBAction)adminRegisterVC:(id)sender{
AdminSignUpViewController *adminSignUpVC = [[AdminSignUpViewController alloc] init];
[adminSignUpVC setDelegate:self]; // Gets an error message. See what error below.
[self.navigationController pushViewController:adminSignUpVC animated:YES];
}
it doesnt work with: adminSignUpVC.delegate = self; either.
error:
No visible #interface for 'AdminSignUpViewcontroller' declares the selector 'setDelegate:'
Is there something i should add to this:
#interface AdminSignUpViewController : UIViewController
I really need some help here!

iOS Exception was thrown: unrecognized selector sent to instance

I have a problem. I am calling a method in another class. I call it before and it works perfect but I call back in another method near the end of the class and I have this error:
-(void)methodOne:(NSString*)myString
{
mySecondClasss *second = [[mySecondClasss init] autorelease];
[second doSomething:myString];
/*
more code
*/
}
-(void)methodTwo:(NSString*)myString
{
mySecondClasss *second = [[mySecondClasss init] autorelease];
[second doSomething:myString];
/*
more code
*/
}
In the second I'm getting this error:
Exception was thrown: -[mySecondClasss doSomething:]: unrecognized selector sent to instance. I don't understand why works once but not the second time. Any of you can give me some pointers of how can I fix this?
I'll really appreciate your help.
Since IOS 5 you have ARC (Automatic Reference Counting) which is automatically releasing the object correctly. Anyway you are not allocating the memory for the mySecondClasss class. Not sure why it even worked in the first method.
Instead of using
mySecondClasss *second = [[mySecondClasss init] autorelease];
Try using
mySecondClasss *second = [[mySecondClasss alloc] init];
Are you sure that you are sending a string to the function? The error implies that the function is not getting a string.
For example:
[self methodOne:#"Properly formatted string"];

Resources