Ok, I've been looking through forums the past couple of days and trying every way that I can to disable this button, but nothing is working. I'm assuming that it's just some syntax I need due to the way that I'm calling the view controller. I can change label texts, but not alter buttons in any way. Here's what I have tried to change the button, but nothing is working:
in my .h file, linked with the button with control-drag:
#property (weak, nonatomic) IBOutlet UIButton *btnDelete;
and here is what I have put in my .m file in the viewDidLoad and also tried in viewDidAppear:
_btnDelete.enabled=false;
_btnDelete.hidden=true;
_btnDelete.userInteractionEnabled=false;
[_btnDelete setEnabled:NO];
[btnDelete setAlpha:0.0];
[btnDelete setNeedsDisplay];
None of these appear to do anything to the button.
Here is how I am calling the view controller that has the button on it.
Detail *Det = [self.storyboard instantiateViewControllerWithIdentifier:#"Detail"];
[Det setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentViewController:Det animated:YES completion:nil];
I also tried to add the following lines right after the above, just to see if that would work, but it did not.
Det.btnDelete.enabled=false;
Det.btnDelete.hidden=true;
Like I said, I've went through forums and tried to find diff ways to modify the button, but nothing is working. The button is not attributed, just plain text. I cannot modify the button in any way that I can see, but I can modify other controls on the page, like labels, just fine.
Thanks in advance for any help on this.
Related
I've developed for Mac before but this is the first time I've attempted to use the NSPopover control, which seemed like a great idea to start out with but so far is causing me no end of problems. The applciation is a menu bar application. I have two NSButton objects in the NSPopover's view controller, the NSPopover is being created programmatically in another subclass of NSButton, the same button which it is being shown relative to. This NSButton that it is being shown relative to is contained along with some other buttons in an NSMenuItem
The popup, containing the two buttons, is being shown fine (see screenshot below), however, despite the 'Yes' button being highlighted with a focus ring, neither button responds to click events, they do not even graphically click in like I would expect them to.
And this is the code that creates the NSPopover and positions it onscreen:
someViewController *confirmationDialogue = [[someViewController alloc] initWithNibName:#"someViewController" bundle:nil];
popOver = [[NSPopover alloc] init];
[popOver setBehavior:NSPopoverAppearanceMinimal];
[popOver setBehavior:NSPopoverBehaviorTransient];
[popOver setContentViewController:confirmationDialogue];
[popOver showRelativeToRect:NSMakeRect(0, 0, self.frame.size.width, self.frame.size.height))
ofView:self
preferredEdge:NSMaxYEdge];
Has anyone got any kind of solution/workaround to this?
Thanks in advance :)
P.s. This is my first question on SO, so I hope I've provided enough information but I'll give any more details as needed.
I'm trying to add a button to a view programmatically and I'd like it to stay "pushed in" when clicked, until it is clicked again. From what I've read it seems like the button to use for this would be NSPushOnPushOffButton. Here's Apple's discription for it:
The first click both highlights and causes the button to be “pushed
in” if the button is bordered; a second click returns it to its normal
state. This option is called “Push On Push Off” in Interface Builder’s
Button Inspector.
It wasn't working in my program so I made a SSCCE, which I'll include below. My problem is the button isn't staying in when clicked, but rather popping back out like a normal button. I'm not sure if I'm missing something about how this button is supposed to perform or if I'm simply implementing it incorrectly (This is the first time I've tried to do a UI programmatically), but other button types such as NSToggleButton work so unless there is something special about NSPushOnPushOffButton I don't see where I went wrong. if someone could suggest a better solution or explain where I went wrong that would be great. Thanks!
#import "AppDelegate.h"
#implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSRect buttonFrame = NSMakeRect(0,0,200,200);
NSButton *button = [[NSButton alloc]initWithFrame:buttonFrame];
[self.window.contentView addSubview:button];
[button setButtonType:NSPushOnPushOffButton];
}
#end
It seems that you have to set a "bezel style", for example
[button setBezelStyle:NSRegularSquareBezelStyle];
After adding that to your sample code, it worked as expected.
In Xcode (iOS), I have a screen with a combination of buttons and text fields. However, they look different. Is there a way that I can have a button look like a textfield? Or is there a way I can make a textfield act like a button (perform some action when pressed and don't bring up the keyboard)?
Thanks
You can try one of these:
place a transparent (custom with no image) button on top of the text field and attach the desired action to it
show your view in the implementation of the textFieldShouldBeginEditing: UITextFieldDelegate protocol method
Subclassing is also an option, but it will probably complicate your task too much.
If You want to perform an action and do not bring up the keyboard when pressed on UITextField You can do it like this:
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
// do here everything you want
NSLog(#"Pressed on TextField!");
[self.view endEditing:YES]; // Hide keyboard
return NO;
}
This function will be called every time when pressed on textField.
** Don't forget to delegate UITextField.
Note: With this You will face the problem: if keyboard is shown it will not hide, so You need also add -endEditing:YES.
You need to custom one of them ... or both
Exemple : create a class CustomTextField : UITextField
in this class use :
#import <QuartzCore/QuartzCore.h>
Play with style
Late answer, but nevertheless. I did this to make a UIButton look like a UITextField
#property (weak, nonatomic) IBOutlet UIButton *resolutionButton;
And in viewDidLoad:
dispatch_async(dispatch_get_main_queue(), ^{
[[self.resolutionButton layer] setBorderColor: [UIColor colorWithWhite:0.6f alpha:0.6f].CGColor];
self.resolutionButton.layer.cornerRadius = 5.0f;
self.resolutionButton.layer.borderWidth = 0.5f;
}
I implemented the following code in my CustomViewController's method viewDidLoad to switch a label visibility on/off depending on my needs:
- (void)viewDidLoad
{
[super viewDidLoad];
myLabel.hidden=NO;
if (x==1) {
myLabel.hidden=YES;//here is correctly hidden
}
else {
[self.view bringSubviewToFront:myLabel];
if(!myLabel.hidden){
NSLog(#"I'm not hidden!");// the log displays correctly! so myLabel is not Hidden but I can't see it!
[self.view bringSubviewToFront:myLabel];
}
}
MyLabel is declared in CustomViewController.h ("IBOutlet UILabel *myLabel;") and connected to its corresponding UILabel interface in the Xib file.
Why Can't I see it even if its "hidden"property is false?
P.s the UILabel text is assigned to the UILabel interface in the xib file
thanks
Luca
solved thanks guys I feel stupid.the label was out of the stage so I could see it.I just repositioned it and now it is working fine
You got a typo in your code:
Your outlet seems to be myLabel but your if statement using mylabel (Should be with an Uppercase 'L'). Also note that the getter for this property is isHidden and not hidden as you might expected (this is not the source of the problem though, but Apple stating it in their documentation so I thought it was worth mentioning).
EDIT:
You said:
MyLabel is declared in CustomViewController.h ("IBOutlet UILabel *infoPostRist;") and connected to its corresponding UILabel interface in the Xib file.
So, shouldn't you check infoPostRist instead of myLabel then?
You can try to remove it from the view instead :
[myLabel removeFromSuperview];
Did you try your code in (void)viewWillAppear:(BOOL)animated or - (void)viewDidAppear:(BOOL)animated?
Hiding/Showing views when the view controller is loaded may not work properly.
For the sake of knowledge I answer my own question:the problem was that the label was out of the stage so I couldnt see it.I just repositioned it and now it is working fine
I have a button that pretty much takes an entire xib so that I can push another viewController on the screen if any part of the original view is touched. I've created an IBOutlet to this button and it works great, however I don't want the entire window to turn "blue" when it is touched (similar to when a small button is pressed). I've tried the following two methods that I found in a similar SO post: How can I prevent a UIButton from highlighting when pressed?, but neither method works. Is there something else I need to set up?
- (void)viewDidLoad
{
[super viewDidLoad];
self.entireWindowButton.adjustsImageWhenHighlighted = NO;
[self.entireWindowButton setImage: [self.entireWindowButton imageForState:UIControlStateNormal] forState:UIControlStateHighlighted];
}
I realise this is old question but if you set the UIButtons type to custom then "adjustsImageWhenHighlighted = NO" will work and it is set to NO by default.