uibutton hide and dropdown text - objective-c

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.

Related

Xcode Objective-C Mac: How to place object on top of AVPlayerView?

I'm currently working on a game. It plays a movie and the story changes depending on the players actions. I'm using quick time events (press a button in x seconds). When there's a quick time event I want to show the button that has to be pressed and the time left to press that button.
I play the movie(s) using an AVPlayerView. On top of that AVPlayerView I have placed a label. But the label is always invisible. It's because of the AVPlayerView.
So does anyone know a way around this?
Edit
I didn't use any code to place the label on top of the AVPlayerView. I just placed it there in the MainMenu.xib. When I view it in Xcode it looks like this:
But when I run the application it looks like this:
As you can see in the first image, all objects are under "View" and the label appears lower in the list so it should be on top of the AVPlayerView. Xcode displays the label on top of the AVPlayerView (image 1), but when I run the application the label is underneath the AVPlayerView (image 2). So my question was how to display the label on top of the AVPlayerView.
I hope this is enough information ;)
Link your label to an IBOutlet in the ViewController which describes your view and in the viewDidLoad() method write
/*top of your file*/
#property (strong, nonatomic) IBOutlet UILabel *myLabel;
/* other properties */
#implementation MyViewController
- (void)viewDidLoad {
[super viewDidLoad];
/*code*/
[self.view bringSubviewToFront:myLabel];
}
/*rest of your code*/
This should do the trick for you.

the method that handles the button action never inserted when the button is dragged

I am trying to drag a button in the .m file as shown in the image below, but after releasing the mouse button the method that handles the button when clicked was never implemented.
please let me why that method gets never inserted in the .m file??
image:
Choose your ViewController in IB by clicking on the yellow circle with a square inside. Select the third tab on Xcode's right pane. Choose ViewController as your class for this IB item from the combobox. After that, the binding should work.
The storyboard viewcontroller must be a subclassed from the class you are trying to drag into (by default its UIviewController) If it's not then it won't work...
From your storyboard click on viewController and then in the inspector panel on your right change it to the right class and you should be all good.

Window called with "showWindow" not focused

i have a simple cocoa coredata statusbar application with Xcode 4.6.2. This is the situation:
Renamed MainMenu.xib to PreferencesWindow.xib, deleted the mainmenu, created a simple and working coredata function with arraycontrollers and bindings in the window.
I have created a new file->User Interface->Main Menu and named it StatusBarMenu.xib. Added a simple menu to it and removed the main menu.
Created new file->objective-c class->subclass of NSObject and named it StatusBarController.
Here's the code for the interface:
#property IBOutlet NSMenu *statusMenu;
#property NSStatusItem *statusItem;
#property [some items for statusbar image]
implementation:
#synthesize [everything]
-(void)awakeFromNib{
statusItem = [[NSStatusBar systemStatusBar]statusItemWithLength:NSVariableStatusItemLength];
[some string, path and stuff for the images]
statusItem.menu = statusMenu;
statusItem.toolTip = #"";
statusItem.highlightMode = YES;
}
Then I've created another new file->objective-c class->subclass of NSWindowController, named it PreferencesWindowController and leave it as it is.
Then a new file->objective-c class->subclass of NSObjects named PreferencesAppController. Here's the code for .h:
#property (assign) IBOutlet NSWindow *mainWindow;
#property (retain) PreferencesWindowController *prefController;
-(IBAction)showPreferences:(id)sender;
.m code:
#synthesize [everything];
-(IBAction)showPreferences:(id)sender{
if(!self.prefController)
self.prefController = [[PreferencesWindowController alloc] initWithWindowNibName:#"PreferencesWindow"];
[self.prefController showWindow:sender];
}
In the AppDelegate files there's only code for coredata, nothing added.
Then in the PreferencesWindow.xib I've added NSObject (the blue cube) for PreferencesAppController with some bindings: Outlets-> mainWindow binded to the window with the simple coredata function. AppDelegate has the window outlet binded to the same window, then Referencing Outlets->File's Owner delegate, some saveaction and managedobjectcontext.
In the StatusBarMenu.xib i've created a StatusBarController object and binded it to the menu (outlets->statusMenu), created another blue object called PreferencesAppController with Received Actions->showPreferences binded to a menu item.
Then i run the program and everything goes fine: an icon appears in the status bar, the dropdown menu works, if i click on "preferences..." the preferences window appears but... it isn't focused! It's on top of the other windows but i have to click to make it focused.
The coredata saving functions works fine except that i have to manually save with a button, quitting the application from the statusbar menu does not save, but this is a marginal issue.
Why isn't the window focused?
I'm assuming from your description of your app as a “statusbar application” that it is meant to run in the background and not show up in the Dock.
This means that your application is not the active application. The user clicking on your status item and choosing an item from its menu does not change that.
When an application that is not the active application opens a window, that window does not take focus (since this ordinarily would amount to stealing focus from whatever the user has been doing in the application that is active).
So, you need to activate your application.

Click on NSTextField Label to emulate hyperlink to a folder

I have an NSTextField label and I want something to happen when a user clicks on it.
I thought I could create an IBAction and link this to the label but nothing seems to happen.
Any suggestions?
Intentions:
The reason why I am doing this is because I want a label that is a hyperlink to a folder. Perhaps I am taking the wrong approach altogether?
IBAction definition in my PersonController.m
- (IBAction)surnameLabelSelected:(id)sender {
NSLog(#"This should do something!");
}
XIB File
In the XIB file I have made a Received Actions connection between surnameLabelSelected and the StaticText NSTextField label.
You've got a couple options. Francis's answer is one option. Another option is to subclass NSTextField and override -mouseDown:. Something like this (written off the top of my head, not tested):
#interface ClickableTextField : NSTextField
#end
#implementation ClickableTextField
- (void)mouseDown:(NSEvent *)theEvent
{
[self sendAction:[self action] to:[self target]];
}
#end
If NSTextField is closer in style to the appearance you need, this might be the better approach. If you need NSButton's features (highlight upon click, etc) go with Francis's solution.
Labels are non-editable text fields thus don't send actions to their targets. You want to use an NSButton and turn off its border-drawing and size it to fit its text as best as possible to simulate a label.
Another option is to create a transparent button (without title/image/border, momentary push in) in front of the label, with the same frame as label's. And set button's action accordingly.

XIB Displaying SubComponent

I created a custom view, which has one button and one text field , as given below
#interface CommUICustomSignInView : CommUICustomView {
IBOutlet NSButton *pBtn;
IBOutlet NSTextField *pTextField;
NSTrackingArea *pTrackingArea;
NSCursor *pPonitHandCursor;
}
#property (nonatomic,retain)IBOutlet NSButton *pBtn;
#property (nonatomic,retain)IBOutlet NSTextField *pTextField;
All items are linked properly, with the view,
In Another window controller XIB, i have added one tab view, in one of the tab item view, i am going to add this view,
added one tab view and assigning this view as below,
NSTabViewItem *pTabViewItem = [pTabView tabViewItemAtIndex:0];
if(pOfflineCTlist == nil){
pOfflineCTlist = [[CommUIOfflineCTlist alloc]
initWithNibName:#"CommUIOfflineViewController" bundle:nil];
}
[pTabViewItem setView : [pOfflineCTlist view]];
[pTabView selectTabViewItemAtIndex:0];
Now with that, i could able to track the mouse event in customSignInview, in nstrackregion,
but i couldn't see the other controls, sign-in button and text field,
Am i doing something wrong,
Finally i found following way to do this,
1 -- Created a Resource like Button / text field in the Main view,
2 -- Put them over the custom view,
3 -- Link them with the custom view,
now i could able to see it,
Is there any other approach then please suggest me,