I want to make a UIButton call a method in my tableView controller but it crashes every time I press that said button.
This button is located in my cell that as a custom class but I want the action of the button to be done in my tableviewController so I decided to add this code in the "cellForRowAtIndex" method:
cell.DeleteFromDevice.tag = 10;
[cell.DeleteFromDevice addTarget:self action:#selector(deleteVideos:) forControlEvents:UIControlEventTouchUpInside];
It is suppose to call the following method:
-(void)deleteVideos:(UIButton*)sender
What do I do wrong ? Can I make something like that or not ?
here is the error log:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:
'-[VideoTableViewController DeleteVideo:]:
unrecognized selector sent to instance 0x7fabbfe38720'
Related
I want to open up a new view with the identifier AddSourceViewController when a button is clicked. I'm using the following code to do so:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"AddSourceViewController"];
[vc setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentModalViewController:vc animated:YES];
When used in viewDidLoad on an initial view, this code works perfectly and opens up the additional view. However, I have added an IBAction to a button on the initial view and when I add the above code to attempt to open the new view on button click, I just get a Thread 1: breakpoint 5.1 6.1. How can I get this to work on the button action?
EDIT: Better error information below.
2012-11-23 16:33:40.399 Marketr[23454:c07] -[SecondViewController addSourceButton:]: unrecognized selector sent to instance 0x6e2f5c0
2012-11-23 16:33:40.400 Marketr[23454:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SecondViewController addSourceButton:]: unrecognized selector sent to instance 0x6e2f5c0'
Do you have a breakpoint set for your action method? Look on the left side next to the code of this method, to see if there is a blue arrow pointing towards the code.
My popover has a button which when clicked, will display a text in the main view controller.
Here's my code for the button:
- (IBAction)print:(UIButton *)sender {
self.displayText.text= #"Hello World";
}
By the way, I followed the tutorial here.
I tried to run the program and I'm getting this error when I click the "print hello world" button:
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[PopoverViewController
print:]: unrecognized selector sent to instance 0xe379240'
I thought that when it's a button in popover, it's a different case. And i've followed few solutions to this problem (posted also by people who encountered the same problem) already but i can't seem to solve it. Still having errors. Hope you could help me.
Thank you.
When you set the action for the message, you need to send the message to your View Controller instead of to your Popover.
Which you can't really do when you have them in separate xib's.
There are a few different ways of approaching this, one of which would be to implement a delegate in your popover class, and when you create the popover set the delegate to self (the view controller which created it) and implement the delegate method. Then, when you press the button, it calls a function in your popover class which then calls your delegate's method.
I've never seen this response before, where the same action, on different runs of the same app throws different errors.
I have an IBAction for a button (that just logs sender) in an NSViewController subclass that throws the errors upon clicking the button (this is an OSX app). I'm getting these (so far):
-[NSArrayM buttonClick:]: unrecognized selector sent to instance
-[__NSCFDictionary buttonClick:]: unrecognized selector sent to instance
-[__NSCFSet buttonClick:]: unrecognized selector sent to instance
-[NSRunLoop buttonClick:]: unrecognized selector sent to instance
And, the dreaded EXC_BAD_ACCESS.
The only code in this test app is this in the app delegate to instantiate the view controller:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
TestController *controller = [[TestController alloc] initWithNibName:#"TestController" bundle:nil];
[self.window.contentView addSubview:controller.view];
}
And this IBAction in the view controller subclass:
-(IBAction)buttonClick:(id)sender {
NSLog(#"%#",sender);
}
The IBAction which is implemented in the view controller is connected in IB (through File's Owner) to the button which is in its view.
I can't understand how I can get so many different error messages in such a simple program. Could this be a problem with the view controller not being in the responder chain? If so, why should it throw errors, shouldn't the message just get sent up the chain and then be discarded?
I've tried having the controller's view set the controller as the next responder (with [controller.view setNextResponder:controller];), but that just gives me the EXC_BAD_ACCESS error upon launch.
Ok, I fixed this with a pointer from Shane Stanley over at MacScripter (I had made another version in ApplescriptObjC to ask the question over there, but that version worked). It's a matter of memory management -- too easy to forget about that when using ARC. The TestController instance was being deallocated before I was sending the IBAction to it. This explains the variable error messages, because sending a message to a deallocated object can point to anything. The problem was fixed by declaring a property (as retain) for the TestController instance, controller.
I would like to know how to correctly show a view programmatically. I will try to explain what i did so far:
The application has a storyboard with two view controllers. One of them has an identifier: " detailview". When i click on a button on the initial view controller i want to show the view controller with the identifier "detailview". Currently i'm using this code:
TI4ViewController* vc = [self.storyboard instantiateViewControllerWithIdentifier:#"detailview"];
UIWindow* window = [UIApplication sharedApplication].keyWindow;
[window addSubview:vc.view];
This works fine to show the view "detailview". But when i add a button on the detailview controller and add a touchdown event in the TI4ViewController(the view controller that's connected to "detailview") i'm getting an exception while clicking on this button.
I'm getting the following exception:
Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '-[__NSCFType TestDown:]:
unrecognized selector sent to instance 0x6e0f670'
I'm using Xcode Version 4.3.2 (4E2002)
I'm not sure what i'm doing wrong here. I think the ViewController is released, but i'm not sure.
Instead of adding another view you can use segue. You can find an example here
Problem solved. I should have added the TI4ViewController as property of the initial view controller. Now it's removed from memory when you leave the function.
In my app I want to show a button item together the back button in the navigation bar. I read the doc of the UINavigationItem class and I found the property leftItemsSupplementBackButton that seems to be just for me. Then I used this line of code:
- (void)viewDidLoad{
[super viewDidLoad];
[self.navigationItem setLeftItemsSupplementBackButton:YES];
}
But when I run the app I get this error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationItem setLeftItemsSupplementBackButton:]: unrecognized selector sent to instance 0x10faefb0'
and the 0x10faefb0 instance is:
_navigationItem UINavigationItem * 0x10faefb0
From the error seems that self.navigationItem doesn't have this property as is said in the apple class reference. Where i'm wrong?
That's for iOS 5 only. Are you running on iOS 4?