I have a set of UIButtons and a UISegmentedControl with 3 segments inside my storyboard.
The segments of UISegmentedControl should work as following;
When first is selected, show all buttons,
When second is selected, hide Button - Button1 and Button - Button2,
(When third is selected, hide Button - Button1, Button - Button2 and Button - Button3).
What should I do to achieve this?
Assign the view controller to be your segmented control's target and implement the action message. You can either do this in IB or using addTarget:action:forControlEvents: and setting the event type to UIControlEventValueChanged.
In the value change action method hide or show the buttons you want using their hidden property.
Related
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 a NSCollectionView and I am adding my custom view which acts as NSCollectionViewItem for that collection view. In my collectionViewItem, I have a NSButton along with various other elements. I have a method onButtonClick which is connected to that button. Now, suppose I add 5 items of my collectonViewItem on to the collectionView.
How can I get the index of the view from where the button was clicked?
Inside onButtonClick, I tried following code but it always returns 0 regardless of which button I click:
id collectionViewItem = [sender superView];
NSInteger index = [[colloectionView subviews] indexOfObject:collectionViewItem];
What is the right way to achieve this?
you cant return index by clicking a control (which having its own functon).i think you have to see http://andrehoffmann.wordpress.com/2009/08/29/nscollectionview-tutorial-for-dummies-xcode-3-1-3/.
before that check collectionview selection as selectable in attributes inspector.(and also try by disable the button)
I am hiding a UIButton underneath a UITextField. Normally, the UIButton responds just find. However, when I set it to hidden (or when I set alpha to 0), it stops working.
For context, I am including a hidden button under a UITextField because the clickable area to edit the textfield is small--I'd like the user to be able to click anywhere in the neighborhood of the uitextfield in order to make the text field become the first responder. Thus, the code for the button is:
- (IBAction)enterTextField:(id)sender {
[nameTextField becomeFirstResponder];
NSLog(#"Pressed");
}
However, this code does not get called when the button is hidden. Otherwise, it does get called.
Make it a custom button with UIButtonTypeCustom or set the background to clearColor.
I have a NSPanel in my MainMenu.xib called filePanel, it has a NSView called filePanelView. When buttons are clicked, I will load a NSView from a nib and add it to the filePanel like this:
[NSApp activateIgnoringOtherApps:YES];
[filePanel setIsVisible:YES];
[filePanelView addSubview:[fileBrowseViewController browseView]];
The problem is that the controls on these subviews can never be brought into focus. For example, a NSTextfield that is set to be editable is not editable, and doesn't have a focus ring around it when clicked. I can click buttons though. But on another window, a determinate progress bar has it's progress measured in grey instead of blue. Is there something I'm doing wrong in terms of needing to manually set these views as having focus?
I have a UITableView with a custom cell. On the press of a button called Edit, I want a UIButton checkMarkBox to appear on all cells. So initially checkMarkBox is hidden, but when this IBAction method is called for Edit, I want the checkMarkBox to be unhidden. When I do this now, it only unhides the box for the last cell, not all of them. So I need a way to go through every cell in my table view and unhide the check box. I'm thinking some kind of for loop that goes through all the cells will do the trick, but I'm not sure how to get that started.
When the button is pressed, set a BOOL in an instance variable for your class. In cellForRowAtIndexPath, check that BOOL and show or hide the checkMarkBox. In the IBAction for your button, set the BOOL, and then call:
[self.tableView reloadData];