Getting crash when move from on viewcontroller to VC - ios

I have one home screen. And i programatically create two button with action. One will go to sign up screen , and another will go to sign in screen.
I added the both sign in and sign up storyboard identity. But when i move from that home VC to sign in VC and Sign Up VC i am getting crash:
-[ViewController pressSignUp:]: unrecognized selector sent to instance 0x7fbb3a72e3f0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ViewController pressSignUp:]: unrecognized selector sent to instance 0x7fbb3a72e3f0'
*** First throw call stack:
Here is my code:
// create button 1
UIButton* button = [[UIButton alloc] initWithFrame:CGRectMake(0.0, self.view.frame.size.height-50, self.view.frame.size.width/2 , 50.0)];
[button setBackgroundColor:[UIColor colorWithRed:188/255.0f green:155/255.0f blue:211/255.0f alpha:0.6f]];
[button setTitle:#"Sign Up" forState:UIControlStateNormal];
[button addTarget:self action:#selector(pressSignUp:) forControlEvents:UIControlEventTouchUpInside];
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; // title color
[self.view addSubview:button];
// Button Two
UIButton* button1 = [[UIButton alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height-50, self.view.frame.size.width/2 , 50.0)];
[button1 setBackgroundColor:[UIColor colorWithRed:188/255.0f green:155/255.0f blue:211/255.0f alpha:0.6f]];
[button1 setTitle:#"Sign In" forState:UIControlStateNormal];
[button1 addTarget:self action:#selector(pressSignIn:) forControlEvents:UIControlEventTouchUpInside];
[button1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; // title color
[self.view addSubview:button1];
// Border color for one button
UIView *leftBorder = [[UIView alloc] initWithFrame:CGRectMake(0, 1, 1, button.frame.size.height)];
leftBorder.backgroundColor = [UIColor colorWithRed:237/255.0f green:211/255.0f blue:246/255.0f alpha:0.6f];
[button1 addSubview:leftBorder];
-(void)pressSignUp
{
UIViewController *secondViewController =
[self.storyboard instantiateViewControllerWithIdentifier:#"SignUpViewController"];
[self presentModalViewController:secondViewController animated:YES];
// Here You can write functionality
}
-(void)pressSignIn
{
UIViewController *secondViewController =
[self.storyboard instantiateViewControllerWithIdentifier:#"SignInViewController"];
[self presentModalViewController:secondViewController animated:YES];
// Here You can write functionality
}
Why i am getting that crash.It any possible to move to Another Vc.
Please help thanks

You forget to implement the parameter for the sender:
-(void)pressSignUp:(UIButton*) sender {
}
-(void)pressSignIn:(UIButton*) sender {
}
And maybe you did not set the identifier in the interface builder:
It's under the Identity Inspector tab in IB. It's called "Storyboard ID". E.g.: SignUpViewController

Related

iOS click on dynamic UIButton crashes

I'm creating programmatically a UIButton with an Image.
UIButton * bericht = [[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width- height, 0, height, height)];
[bericht setBackgroundImage:[UIImage imageNamed:#"bericht.png"] forState:UIControlStateNormal];
[bericht addTarget:self action:#selector(imageClicked:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:bericht];
- (void) imageClicked:(UIButton *) sender {
NSLog(#"test message");
}
When I click on this button I got the following error code:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:
'-[__NSSetM goToFirstTrailer:]: unrecognized selector sent to instance 0x7fdaf1e73fe0'
Does anyone know a solution?
Change your selector method to imageClicked.
UIButton * bericht = [[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width- height, 0, height, height)];
[bericht setBackgroundImage:[UIImage imageNamed:#"bericht.png"] forState:UIControlStateNormal];
[bericht addTarget:self action:#selector(imageClicked:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:bericht];
- (void) imageClicked:(UIButton *) sender {
NSLog(#"iaksdkjas");
}

UISearchBar inputAccessoryView issue

I've crate view controller and add a button as subview.
#implementation PredectiveViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self.view setFrame:CGRectMake(0, 0, 400, 40)];
[self.view setBackgroundColor:[UIColor redColor]];
UIButton *b = [UIButton buttonWithType:UIButtonTypeCustom];
[b setFrame:CGRectMake(200, 0, 200, 40)];
[b setTitle:#"Some button" forState:UIControlStateNormal];
[b addTarget:self action:#selector(tapped:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:b];
}
-(void)tapped:(id)sender
{
NSLog(#"Tapped");
}
Then set controllers view as input view
PredectiveViewController *pred = [[PredectiveViewController alloc] init];
[searchBar setInputAccessoryView:pred.view];
When i pressed the button first time, my program has crashed with error like
"[UIPopoverPresentationController tapped:] unrecognized selector
sent to instance"
But now i have no error on crash.
About hierarchy:
I present view controller A in UIPopoverController, view controller A have UITableViewController as subview, which have UISearchBar, which have inputAccessoryView with UIButton.
Running on iOS 8.
Any suggestion?

link button to view controller programmatically

I am starting with xcode and objective C, maybe my quiestions are basics even repetitive but really already I was looking, please no negative votes n_n
I want to link a button to view controller
Graphically with Xcode I can make it but I need to do it programmatically
button is created with the following code
UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn1.frame = CGRectMake(40, btnp, 100, 30);
btn1.backgroundColor = [UIColor purpleColor];
[btn1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[btn1 setTitle:#"Ingresar" forState:UIControlStateNormal];
[self.scrolling addSubview:btn1];
this button is in principalviewcontroller
then I wanna that
when I click the button a new viewcontroller named "viewcontroller" is opened
how to I do?
Already I was looking and looking and looking but I have not found a solution
I have several days with this, help me please
[btn1 addTarget:self action:#selector(showSecondViewController) forControlEvents:UIControlEventTouchUpInside];
then create the method
- (void) showSecondViewController {
SecondViewController * secondVC = [[SecondViewController alloc] init];
[self.navigationController pushViewController:secondVC animated:YES];
}

Error with customized button

I have an error:
2013-08-01 01:09:18.433 VstupHelper[28332:11303] -[VHMasterViewController popViewController:]: unrecognized selector sent to instance 0x7566410
2013-08-01 01:09:18.434 VstupHelper[28332:11303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[VHMasterViewController popViewController:]:
Here is my code:
UIButton *bt=[UIButton buttonWithType:UIButtonTypeCustom];
[bt setFrame:CGRectMake(0, 0, 50, 30)];
[bt setImage:[UIImage imageNamed:#"menu.png"] forState:UIControlStateNormal];
[bt addTarget:self action:#selector(popViewController:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *leftButton=[[UIBarButtonItem alloc] initWithCustomView:bt];
self.navigationItem.leftBarButtonItem=leftButton;
self.navigationItem.leftBarButtonItem.target = self.revealViewController;
self.navigationItem.leftBarButtonItem.action = #selector(revealToggle:);
I'm not good at English, so I apologize if I'm hard to understand.
You have several problems:
1) You are calling popViewController: on what I asssume is a UIViewController subclass, when you should be calling it on your UINavigationController.
2) popViewController: takes a bool value for whether to animate that transition. With the action, it gets passed the sender by default.
3) You then reassign the target and action for the button (but these don't get called when you create the UIBarButtonItem using the initWithCustomView: initializer: See docs).
How to fix this:
1) Call a method you create for the button handler:
UIButton *bt=[UIButton buttonWithType:UIButtonTypeCustom];
[bt setFrame:CGRectMake(0, 0, 50, 30)];
[bt setImage:[UIImage imageNamed:#"menu.png"] forState:UIControlStateNormal];
[bt addTarget:self action:#selector(buttonTouched:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *leftButton=[[UIBarButtonItem alloc] initWithCustomView:bt];
self.navigationItem.leftBarButtonItem=leftButton;
2) In that method, pop the view controller, or do whatever you actually want to do:
- (void)buttonTouched:(id)sender
{
[self.navigationController popViewController:YES];
//Or what you assigned to the button action:
[self.revealViewController revealToggle:(not sure what you're supposed to have here)];
}

Why send addTarget Method have the : to work

Hoping someone can help me with why I should add a : to invoke the method.
Here is the viewDidLoad method
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor= [UIColor yellowColor];
//Add Button
CGRect buttonRect= CGRectMake(100, 100, 100, 44);
UIButton *clickButton=[UIButton buttonWithType:UIButtonTypeRoundedRect];
[clickButton setFrame: buttonRect];
[clickButton setTitle:#"Click Me" forState: UIControlStateNormal];
[clickButton addTarget:self action:#selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:clickButton];
[self buttonPressed:clickButton];
//Add UILabel
CGRect labelViewRect= CGRectMake(50, 30, 200, 44);
UILabel *labelview= [[UILabel alloc]initWithFrame:labelViewRect];
[labelview setText:#"Hello welcome to my app!"];
//Clear the UIView button's background
[labelview setBackgroundColor:[UIColor clearColor]];
[self.view addSubview:labelview];
}
Here is the Button Pressed method
-(void)buttonPressed:(UIButton *)sender{
NSLog(#"This button was pressed");
self.view.alpha=((double)arc4random()/0x100000000);
}
When I remove the : from
[clickButton addTarget:self action:#selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
i.e. am changing this above line to something like this
[clickButton addTarget:self action:#selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside];
An exception is thrown:
2012-12-29 17:56:18.209 AlphaSchoolColor[11414:c07] -[com_skminfotekViewController buttonPressed]: unrecognized selector sent to instance 0xde2f050
2012-12-29 17:56:18.210 AlphaSchoolColor[11414:c07] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[com_skminfotekViewController buttonPressed]: unrecognized selector sent to instance 0xde2f050'
Question to community is what is happening with that : and where are some more information I can learn about its importance.
Thanks.
Your method has an arg. If you want to send action without the ":" then change your method.
-(void)buttonPressed{
}

Resources