UIActionSheet - add disabled button - objective-c

Is there a way to add a disabled (non-clickable, greyed out) button to a UIActionSheet?
All I see is "addButtonWithTitle" which does not supply any properties to work with.

I believe there is no way to add disabled button in a UIActionSheet. From the class reference:
Use the UIActionSheet class to present the user with a set of
alternatives for how to proceed with a given task. You can also use
action sheets to prompt the user to confirm a potentially dangerous
action. The action sheet contains an optional title and one or more
buttons, each of which corresponds to an action to take.
If the button is disabled, it should not be added into the UIActionSheet in the first place since it is not an alternative on how to proceed with a given task.

UIActionSheet's interface doesn't really give you much control over appearance of the the whole view or the buttons.
You can use some other libraries. If you can't find one that gives such control, it would be simple to you to add that functionality. For example JLActionSheet or RDActionSheet.
You can also, try to retrieve the subviews of UIActionSheet by traversing the view stack recursively. self.view.subviews or by [[UIApplication sharedApplication].windows[0].subviews] "try both, I don't know which one is the right one". You can find the views using introspection, and find the button you want to disable.

Related

Correct way to make an NSView the firstresponder to all Undo/Redo actions irrespective of active/focused view/control

I have a standard document based application whose main window has two NSViews.
Is it possible to make NSView1 the firstresponder for Undo/Redo actions even when NSView2 is the focused view.
Is it possible to have the context for Edit menuitem permanently set to NSView1's context. E.g. if an NSTextField in NSView2 has focus and the Edit menu item is opened, by default it opens in the context of NSTexfield's current state, can this be overriden?
If either is possible, how does one go about achieving this?
C.
Ok, found the solution, there's a rather convenient method in NSResponder called validateProposedFirstResponder. With a little manoeuvring, one should be able to achieve the desired effect.

Custom "undo" for Webview

OK, here's the situation. I have:
A Webview
Lots of NSTextFields
Other unrelated controls
Normally, the Edit > Undo menu item links to First Responder's undo: action. And everything works fine + you can even "undo" while typing in an NSTextField.
Now, what if I want to handle this "undo" action, in a different way, only for my WebView.
I've been thinking of two approaches:
Link the "Undo" item to a custom action and check who is the First Responder. If it's the Webview, then do what needs to be done. Else, "pass" the event to the control. (However, when attempting a [FIRST_RESPONDER performSelector:#selector(undo:)], first it doesn't seem to recognize the selector and last but not least nothing happens.)
Link the "Undo" to the first responder's undo:(as usual), subclass the Webview and add a custom - (void)undo:(id)sender action. In that case though, when the webview is active, the "Undo" item is grayed-out, so I can't do anything whatsoever, not even check whether the custom method would be called.
Suggestions? How would you go about that?
What am I missing?
I think this is the answer: https://developer.apple.com/library/mac/documentation/Cocoa/Reference/WebKit/Protocols/WebEditingDelegate_Protocol/
Also reference this: Removing undo actions for a WebView's NSUndoManager

How do i add a right-click option to a menulet in Xcode and Interface Builder?

I'm trying to have a menulet that acts different on left-click and on right-click (and maybe combinations in the future like control-click, option-click or command-click).
Right now I have a menulet with a statusMenu attached to it that opens on left- and on right-click. In the statusMenu are five options: one execution item, three preference-setting-items and one quit item.
I'd like to separate the behavior somewhat as the menulet is designed to be a one trick pony. Left-clicking it should execute the function, right-clicking should open the menu exactly as it is (including the execution).
Any ideas how to do this?
Right now I'm calling the statusMenu from the code as is usual with statusMenus
[statusItem setMenu:statusMenu];
To do this, you will need to display the menu manually. One way to do it is to create a custom view and place that in the status item, and then use the mouseUp: and rightMouseUp: event handlers to perform your actions. You can also get the modifier keys from the event to perform other actions. It may also be possible to use the built-in target-action mechanism of the status item, and get the information from the NSEvent class methods +pressedMouseButtons and +modifierFlags. Either way, you can display your menu using NSStatusItem's -popUpStatusItemMenu: method.
For an example of handling left and right clicks with a custom view, see my answer to this question.

NSTableView responding to first click in a panel

I have noticed in the Interface Builder if I want to click on or drag from the Library panel, I only have to click on it once, even if the Library panel does not have the current focus.
I am trying to build a panel that behaves similarly.
Is there any simple way to let the NSTableView accept the click, even if the window does not have the focus?
Thanks.
Ok, I found the answer. Inside from awakeFromNib I call this:
[self setBecomesKeyOnlyIfNeeded:YES];
It seems to do the trick. It's a little bit different from Interface Builder where the Panel actually gets the focus simultaneously with a single click, but doing it this way is just what I was looking for.
Your view should override -acceptsFirstMouse: to return YES (or evaluate the event passed to you to determine what to return). You'll have to subclass NSTableView to do that of course.

How would you make a Button display a Menu when clicked?

I am looking for some code to make a Menu appear next to a button when it is clicked.
What code would I need for this?
Sorry if this sounds a bit vague.
Why not use NSPopUpButton?
NSPopupButton was my first thought as well. It's how apps with the "action gear" buttons accomplish their menus.
If you do have something else in mind though, look at NSMenu's +popUpContextMenu:withEvent:forView:. Just hook an action method up to your button, create an NSMenu and populate it with NSMenuItems, and send it to this method along the the current event from NSApplication's currentEvent getter.
If you really need to roll this yourself, rather than using one of the built-in controls that shows a menu, you can create an NSPopupButtonCell and use that to show the NSMenu:
NSPopUpButtonCell *popupCell = [[NSPopUpButtonCell alloc] initTextCell:#"" pullsDown:YES];
[popupCell setMenu:yourMenu];
[popupCell trackMouse:event inRect:[yourButton bounds] ofView:yourButton untilMouseUp:YES];
[popupCell release];
You'd want to adjust the pullsDown:, inRect:, and ofView: arguments as necessary to position the menu the way you want.