I have a problem with the button, it's weird but it disappears.
I click on it and it brings me to an other view and then i click back and i am back in my Mainview but without button.
I've added this button in storyboard - not progamatically.
Time to start debugging: Start by putting a breakpoint on viewDidAppear: and in the console type:
po self.whateverYourButtonIsCalled
Check frame, isHidden, the superview's subviews, transforms, etc.
Related
I am on objectiveC, OSX, not iOS. XCode 8.3
I have a preferences Window (custom NSWindow) that opens as a modal on my main window.
The preferences window itself contains a view with tabs. The tab height changes the windows size whenever one is clicked.
First Tab clicked:
Second Tab clicked:
Now if someone hides the application in the dock and activates it again, the preferences window becomes active with the height of tab 1, even if tab 2 is still active. So the content gets cut off.
What i need is some kind of notification that gets triggered on becoming active/visible again to trigger a resize of the window before it gets displayed.
I tried it with these notifications in my NSWindow subclass (with NSWindow delegate set).
- (void)windowDidResignMain:(NSNotification*)notification{
NSLog(#"windowDidResignMain");
}
- (void)windowDidResignKey:(NSNotification*)notification{
NSLog(#"windowDidResignKey");
}
- (BOOL)canBecomeKeyWindow{
return YES;
}
- (BOOL)canBecomeMainWindow{
return YES;
}
But none of them worked. Is it because it's a modal window?
Any help appreciated.
I found it. My mistake - my tabViewController triggered a resize on viewWillAppear with always the first tab. I changed that to the current selected tab and that was it.
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.
I have two buttons on top of each other in my nib. I need both of them to be pressed when tapped, but only the top button carries out its function. Is there a way for the top button to tell the bottom button to activate when the top one gets pressed. I do not think I can just merge the buttons into one and use one -(IBAction)buttonName function because one button is bigger than the other so I do not always need both to activate when one of them is pressed.
Thanks!
Is there a way for the top button to tell the bottom button to
activate when the top one gets pressed.
Not really, but you can have the action for the top button call the action for the bottom button.
Here's one way:
- (IBAction)actionTop:(id)sender
{
NSLog(#"The top button was activated.");
[self actionBottom:self];
}
- (IBAction)actionBottom:(id)sender
{
NSLog(#"The bottom button was activated.");
}
Another way would be to use the same action for both, and figure out what to do based on which button triggered the action:
- (IBAction)action:(id)sender
{
// if the top button was tapped, do this part
if (sender == self.topButton) {
NSLog(#"The top button was activated.");
}
// you want the bottom button to be activated no matter which button was tapped, so
// no need to check here...
NSLog(#"The bottom button was activated.");
}
the bottom button is the whole screen which changes what is displayed.
the top button plays a sound, except there are 4 top buttons that
plays different sounds
It seems like an invisible button covering the whole screen might be the wrong way to tackle the problem. You might look into using a gesture recognizer attached to your view to trigger the change. Your button actions could call the same method that the gesture recognizer uses.
Since one button is larger than the other, I assume that you would like the smaller button to "bring down" the larger button with it, including the change in the visual state. In cases like that you could send your target button a "tap" programmatically, like this:
- (IBAction)largeButtonClick:(id)sender {
}
- (IBAction)smallButtonClick:(id)sender {
// Perform the acton specific to only the small button, then call
[largeButton sendActionsForControlEvents:UIControlEventTouchUpInside];
}
I have NSTableView and NSView inside of this table using as cell. This NSView has 3 NSTextFields.
When I'm trying to select one of this NSTextFields they respond really quickly. But if I add some code to register double click event on NSTableView, delay appears. So when I click on textfield it thinks half a second and then activates it. But there is no such delay without double click event registered.
My code:
-(void)awakeFromNib{
[tasksList setDoubleAction:#selector(doubleClickInTable:)];
[tasksList setTarget:self];
}
-(void)doubleClickInTable:(id)sender
{
//Don't matter, it can be empty.
}
I have a set of UIButtons (defined in a xib) who have labels that need to be updated periodically. In the ViewDidLoad method of the view controller of those buttons' superview, I have an update method that does, for each button:
button.titleLabel.text = #"Relevant Text";
[button setNeedsDisplay];
and when you tap a button, another method runs which pops up a UIAlertView, which in turn calls back a method on the view controller which does much the same thing as the initial text setting method:
button.titleLabel.text = #"New Text";
[button setNeedsDisplay];
however, this code simply isn't working, the button label's text doesn't get updated in either method, it remains a blank white button. In the xib I don't define any text on the buttons - there's no point, the button text doesn't make sense unless it's set at runtime. Anyway, on a lark, I decided to set the text of one of the buttons to "test test test".
Now, when I tap that particular button, it pops up the UIAlertView but in the background changes the text of the button to "test test test test". And this time, the UIAlertView callback does what I expect it to and sets the text for only that button. When I hit it again, the text goes back to "test test test test" until I dismiss the UIAlertView, which again will run the callback method and set the button text to whatever the method should.
I have no idea what's going on here, or why setting the text initially in the xib has any relation to whether or not I can set that text later programatically. Obviously this isn't the behavior I want, I want to know how to for sure set the text on the buttons.
Edit: SVD's advice about setTitle:ForState: solved my problem, thanks. I'm still curious though as to why the title label set in the .xib shows up, but only when I have a UIAlertView pop up.
You may need to use [setTitle: forState:] to set the button title for normal and highlighted (or selected) state.
(And do make sure the button is connected to the outlet, as jtbandes points out).