i have a problem with and IBAction in my code. Everytime i click the button this Exception appears:
2013-01-15 22:25:00.798 FitnessApp[3478:c07] -[__NSCFString cancel:]: unrecognized selector sent to instance 0x93a7e50
2013-01-15 22:25:00.800 FitnessApp[3478:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString cancel:]: unrecognized selector sent to instance 0x93a7e50'
i already searched for this error. however the solutions here on stackoverflow didnt work.
My connections are all correctly set. no dublicate connections or something like that.
My Code:
- (void)viewDidLoad {
[super viewDidLoad];
[self setTitle:NSLocalizedString(#"Placeholder_Description", nil)];
[self.navigationController setToolbarHidden:NO];
[self.navigationController.toolbar setTintColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:1]];
[self.buttonCancel setTarget:NSLocalizedString(#"Cancel_Button", nil)];
[self.buttonSave setTarget:NSLocalizedString(#"Save_Button", nil)];
[self.textViewDescription.layer setBorderColor:[[UIColor grayColor] CGColor]];
[self.textViewDescription.layer setBorderWidth:1.0];
[self.textViewDescription.layer setCornerRadius:8.0f];
[self.textViewDescription.layer setMasksToBounds:YES];
[self.textViewDescription setText:[self textViewDescriptionText]];
}
- (IBAction)cancel:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)save:(id)sender {
[self.delegate doSaveDescription:self withDescription:[self.textViewDescription text]];
[self dismissViewControllerAnimated:YES completion:nil];
}
i made some NSLogs to find out that the IBAction is the problem because there never was an output after clicking the buttons, just the exception.
So what can i do if the connections are correctly set?
Related
I am coding an app that involves loading data from NSUserDefaults. So when I have confirmed that the passed integer was 1, I want it to display a certain text. However when I don't have a UILabel on my .Xib. It is fine, but as soon as I add a outlet for the label, place it onto the .Xib and link it all up, it comes up with SIGABRT
-(void)viewDidLoad {
int page = [[[NSUserDefaults standardUserDefaults] objectForKey:#"Page"] integerValue];
NSString *log = [NSString stringWithFormat:#"%d", page];
NSLog(log);
if (page == 1 ) {
NSLog(#"redstone block");
title.text = #"redstone Blcok";
}
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
The error I get:
2013-04-09 18:16:13.910 redstoneGuide[94905:c07] -[UILabel copyWithZone:]: unrecognized selector sent to instance 0x756b910
2013-04-09 18:16:13.911 redstoneGuide[94905:c07] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UILabel copyWithZone:]: unrecognized selector sent to instance 0x756b910'
* First throw call stack:
(0x1599012 0x12a6e7e 0x16244bd 0x1588bbc 0x158894e 0x12baae9 0x2cd32b 0xcd45be 0xcd40e7 0xcfeb58 0x408019 0x12ba663 0x159445a 0x406b1c 0x2cb7e7 0x2cbdc8 0x2cbff8 0x2cc232 0x2d7c25 0x4d73a3 0x2d4ee3 0x2d5167 0x33cc 0x12ba705 0x1ee2c0 0x1ee258 0x2af021 0x2af57f 0x2ae6e8 0x4b21d3 0x1561afe 0x1561a3d 0x153f7c2 0x153ef44 0x153ee1b 0x25fa7e3 0x25fa668 0x1eaffc 0x1fcd 0x1ef5)
libc++abi.dylib: terminate called throwing an exception
(lldb)
It turns out you cannot do
Iboutlet uilabel *title;
The name title causes the application to crash.
However, the below works.
Iboutlet uilabel *Gtitle
I have error:
[2194:c07] CoreData: error: Failed to call designated initializer on NSManagedObject class 'Event'
2012-12-08 12:00:57.505 eventCost[2194:c07] -[Event setType:]: unrecognized selector sent to instance 0x7456dd0
2012-12-08 12:00:57.523 eventCost[2194:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Event setType:]: unrecognized selector
I have protocol at my addEventController:#protocol
AddEventControllerDelegate
- (void) addEventControllerDidSave:(NSString *) typeText;
- (void) addEventControllerDidCancel:(Event *) personToDelete;
#end
the implementation of the protocol:
- (void) addEventControllerDidCancel:(Event *)EventToDelete{
[[self currentPerson] removeEventsObject:EventToDelete];
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void) addEventControllerDidSave:(NSString *)typeText{
Event *newEvent = [[Event alloc]init];
[newEvent setType:typeText];
[currentPerson addEventsObject:newEvent];
[self dismissViewControllerAnimated:YES completion:nil];
}
also I have this segue for add new event:
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([[segue identifier]isEqualToString:#"addEvent"])
{
AddEventController *aec = (AddEventController *) [segue destinationViewController];
aec.delegate = self;
}
}
I just try to add new Event with type property but I have this error and I don't understand what wrong..
The problem is that you're trying to send an NSManagedObject an init message.
You need to use - (id)initWithEntity: (NSEntityDescription *) entity insertIntoManagedObjectContext: (NSManagedObjectContext *) context
see the documentation here: https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/CoreDataFramework/Classes/NSManagedObject_Class/Reference/NSManagedObject.html
I found some answers to my question but it still does not work. I have setup a button in IB and I want to setup the action and target by code(just for learning). I have a function in my MainViewController:
- (IBAction) onSpecialCase:(id)sender {
NSLog(#"It's working");
}
In the viewDidLoad function I do this:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[myButton setTarget:self];
[myButton setAction:#selector(onSpecialCase:)];
}
Xcode already marks these lines telling me: "UIButton may not respond to 'setTarget'". When running the app anyways it terminates saying:
-[UIRoundedRectButton setTarget:]: unrecognized selector sent to instance 0x4b47e30
2011-06-29 08:12:22.465 FirstTry[3765:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIRoundedRectButton setTarget:]: unrecognized selector sent to instance 0x4b47e30'
That's what I could expect from the XCode warning, but why is that? Every example I find on the web is exactly like mine. Adding the actionMethode to the button via IB works like expected. What am I doing wrong?
first check if you have declared the button as an outlet, second you should check if you connect the outlet to the button or use what I usually do is to add new button in code
UIButton *Button=[UIButton buttonWithType:UIButtonTypeCustom] ;
Button.frame=CGRectMake(0,0,30,30); // place your button
[Button addTarget:self action:#selector(processButtonCLick) forControlEvents:UIControlEventTouchUpInside];
[Button setImage:[UIImage imageNamed:#"imageoricon.png"] forState:UIControlStateNormal];
[self.view addSubview:Button];
It may help you.
UIButton *sendButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[sendButton setTitle:#"Send" forState:UIControlStateNormal];
[sendButton.titleLabel setFont:[UIFont boldSystemFontOfSize:12]];
sendButton.frame = CGRectMake(0, 3, 67, 37);
[sendButton addTarget:self action:#selector(sendButtonClicked) forControlEvents:UIControlEventTouchUpInside];
(IBAction)switchAppointment {
AppointmentController *appt = [[AppointmentController alloc] initWithNibName:nil bundle:nil];
appt.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:appt animated:YES];
[appt release];
}
That is the code that I use to switch from one .xib to another, however on the line that says "self presentModalViewController:appt animated:YES" , I'm getting a SIGABRT error. My app crashes immediately when I try to go into that interface.
FYI too I'm on Xcode 4.2, but it was doing this before I downloaded the beta.
I have also same answer for the code:
nextView *second=[[nextView alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:second animated:YES];
[second release];
Yours
Miska
I am trying to display a custom sheet in my application, but I think I am doing something wrong. While everything seems to be working just fine, I have a rather odd side-effect. (which took hours to figure out). It turns out that everytime I display a sheet in my application, the Application delegate gets set to the instance of the sheet, thus my Controller gets unset as the delegate causing all sorts of problems.
I've created a NIB file which I called FailureSheet.xib. I laid out my interface in IB, and then created a subclass of 'NSWindowController' called 'FailureSheet.m' which I set to the File's Owner. Here is my FailureSheet class:
#import "FailureSheet.h"
#implementation FailureSheet // extends NSWindowController
- (id)init
{
if (self = [super initWithWindowNibName:#"FailureSheet" owner:self])
{
}
return self;
}
- (void)dealloc
{
[super dealloc];
}
- (IBAction)closeSheetTryAgain:(id)sender
{
[NSApp endSheet:[self window] returnCode:1];
[[self window] orderOut:nil];
}
- (IBAction)closeSheetCancel:(id)sender
{
[NSApp endSheet:[self window] returnCode:0];
[[self window] orderOut:nil];
}
- (IBAction)closeSheetCancelAll:(id)sender
{
[NSApp endSheet:[self window] returnCode:-1];
[[self window] orderOut:nil];
}
#end
Nothing complex going on here. Now this is how I display the FailureSheet in my 'Controller' class:
sheet = [[FailureSheet alloc] init];
[NSApp beginSheet:[sheet window]
modalForWindow:window
modalDelegate:self
didEndSelector:#selector(failureSheetDidEnd:etc:etc:)
contextInfo:nil];
Now if I log what the [NSApp delegate] is before displaying my sheet, it is <Controller-0x012345> which is correct. Then, after running this code and my sheet is up, if I log it again it is <FailureSheet-0xABCDEF>.
Not sure what I'm doing wrong here - Any ideas?
This is one of those "I'm-an-idiot" answers.
Turns out I at some point I accidentally made a connection in my sheet's NIB file between the Application and the File's Owner (FailureSheet) setting it as the delegate. So, everytime it got loaded it overwrote the existing delegate connection I had in my MainMenu NIB file.