in .h file I write
-(IBAction)openShuffleForm;
and .m
-(IBAction)openShuffleForm{
NSLog(#"XXXXXXX");
}
and connect with even touch up inside
but when I run my program it error show this message
-[UITouchData openShuffleForm]: unrecognized selector sent to instance 0x391cc20
** What happen I don't know why?
Did you create the link between the button and the implementation? The implementing class should have an IBOutlet of type UIButton. Bind the IBOutlet to the button in Interface builder. This will cause the button to automatically be instantiated when the view is rendered and the BAD ACCESS should be alleviated.
In my case it was a modal window which I released after opening. Thus any button which I clicked to try to call ANY IBAction would not work from that Modal View and kill the app with SIGBART or BAD_EXEC errors.
Related
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 use a xib file to show an NSWindow named mainWindow - now I want to get a reference to mainWindow via code (e.g. NSWindow *mainWindow). I can't find anything in the documentation, any pointers?
The xib file will have placeholder objects in it for the app delegate and / or the file's owner.
On the assumption that it has the app delegate in it, you can get a reference to the window or any object in the xib by
Declare a property in the app delegate of the right type and with IBOutlet as part of its type:
#property (weak) IBOutlet NSWindow* theWindow;
Locate the app delegate object in the xib. Click and drag it while the control key is pressed. You should get a line between the mouse pointer and the object.
Drag on to the window and release the mouse button.
You should see a list of the outlets in the app delegate. Select theWindow and your done.
I have a signup button that switches screens for a signup form. I'd like for it to hide the button and drop down text boxes beneath when the button is tapped (instead of switching screens). Is this possible? Currently I have in my .h file...
#property (nonatomic, strong) IBOutlet UIButton *emailSignUp;
- (IBAction)hideButton:(id)sender;
and in the .m file my method is as follows
- (IBAction)hideButton:(id)sender {
[self.emailSignUp setHidden:YES];
}
However it seems to be crashing whenever I try to test. Any advice? I thank you guys in advance. I know there is a long way to go, but I feel this is my first step.
It sounds like you haven't connected the button you created in the Interface Builder portion of Xcode to the emailSignUp IBOutlet. You can do this by going to the Interface Builder, selecting File's Owner and then the Connection Navigator (in the right side panel, designated by the arrow icon in the tab bar). Then, drag from the Outlet to the button.
In Objective C (Cocoa) I have an app running with a modal sheet, but I want to allow the app to quit even when the sheet is displayed (contradicting the definition of modal I think, but I like the animated effect of modal sheets).
I'm already using the -setPreventsApplicationTerminationWhenModal method and it works fine, but I'm wondering... is there any way to keep the close button enabled? The little circle usually red-colored close button that comes with all windows in the top left corner (side by side with minimize and maximize)? Right now it's completely disabled when the sheet is running, and it would be awesome if there is a way to enable it.
Thanks!
Use a delegate method to close the Modal View. You declare the delegate on your modal view controller and that delegate method dismisses the ModalViewController
In the Modal ViewController Interface File:
#protocol MyViewControllerDelegate
-(void)dismissModal;
#end
Then declare the delegate as a class property in the Modal ViewController:
#property (nonatomic, retain) id <MyViewControllerDelegate> delegate;
Now, declare your parent ViewController as a proper delegate implementer for the Modal ViewController:
#interface MyParentViewController : UIViewController
Then in the calling (parent) ViewController implement the delegate method in the implementation file:
-(void)dismissModal
{
// Dismiss the Modal ViewController that we instantiated earlier
[self dismissModalViewControllerAnimated:YES];
}
That should do it. The advised way to handle this is through delegate methods (and delegate methods are so handy to use whenever a process in one controller needs to fire a method in another controller. It is well worth the time to get familiar with using delegates to get work done in Obj C
Sorry - this may be an easy question, I'm new to iPhone development and still wrapping my head around Views vs ViewControllers.
I have a NavigationViewController and I can push Views using the following method in the RootViewController which is connected to a Bar Button Item:
- (IBAction)switch:(id)sender {
NSLog(#"Swith...");
LibraryViewController *varLibraryViewController = [[LibraryViewController alloc] initWithNibName:#"LibraryViewController" bundle:nil];
[[self navigationController] pushViewController:varLibraryViewController animated:YES];
}
I want to call this same method from a button on the same view that is currently loaded. Basically I want to have the Bar Button at the top call the same method as a button on the view. I was wondering how to call a method in the ViewController from the view loaded from that viewController. Hopefully that makes sense.
Do I need to create an instance of the RootViewController? I would think that would already be instantiated. Thank you.
BTW, the code you have pasted there is leaking your LibraryViewController. You need to either explicitly release it after pushing it, or autorelease it when it's created.
Your RootViewController should have its own xib file. In this xib, the RootViewController is represented by the object named "File's Owner". You can link buttons on the view to File's Owner the same way you can link things to RootViewController in MainMenu.xib.
You'll want to declare your method as an IBAction in your header file:
- (IBAction) myMethod: (id) sender;
Save your header, then switch to Interface Builder. Right click on the Bar Button, and drag from the selector tag to your view controller object (probably the File Owner). When you release, you should be given a popup menu of available actions, and myMethod should be selectable.
If you don't get this popup, you may need to make sure your File Owner class is set properly: select the File Owner in the file window, then select "Tools" > "Identity Inspector" from the menu. In the inspector, type your view controller's class into the Class field.