I have to following code
-(IBAction)doVibrate{
[self vibrate];
}
-(void)vibrate{
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
both doVibrate and vibrate are is same class .but when i am clicking the button associated to the doVibrate it device not vibrating .
I have imported the AudioToolbox/AudioToolbox.h and AVFoundation/AVFoundation.
Can some one tell me where i am wrong.
Thanks
IBActions are usually of the following form:
- (IBAction)vibrate:(id)sender;
Note that the following 3 methods are all different:
- (IBAction)vibrate:(id)sender;
- (IBAction)vibrate; // no sender argument
- (void)doVibrate;
Here is what I would do. In your .h file, define the following method:
- (IBAction)vibrate:(id)sender;
// - (IBAction)vibrate; comment out this method
In your .m file, do the following:
- (IBAction)vibrate:(id)sender {
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
Now, when you save your .h and .m files, and switch back to your nib/xib file in Interface Builder, it may show a yellow warning message that "'vibrate' is no longer defined in "your class name here'. That's okay, as the following should remove that error. Control-click (or right-click) on the button and drag to your controller class and choose "vibrate:" as the method name to call (note the colon, :, in the method name).
Related
I'm working on an installer plug in which currently looks like this:
Currently I disable the "Continue" button with [self setNextEnabled:NO] until all fields are input. What I would like to be able to do is actually run some code when the next button is clicked. Here I would ping the server, and only actually go to the next pane if I get pong.
How do I have a listener for this button?
My code goes a little like this:
#import "MyInstallerPane.h"
#implementation MyInstallerPane
- (void)didEnterPane:(InstallerSectionDirection)dir{
[self toggleContinueButton];
[self initTempDir];
}
.. + my own functions..
You can override the delegate method
- (BOOL)shouldExitPane:(InstallerSectionDirection)dir;
A subclass should override this method if it needs to prevent the
InstallerPane from exiting. Called to determine if a pane should exit
and allow another pane to be display on screen. Once the InstallerPane
decides it is time to exit, it can call gotoNextPane or
gotoPreviousPane to exit without calling shouldExitPane again.
For example:
- (BOOL)shouldExitPane:(InstallerSectionDirection)dir {
if (!good) {
return NO
}
return YES
}
The project have some views with different buttons. When I hide a view and show the other view, I can't get the focus on my button.
I think is related to setNeedsFocusUpdate. I have read the Apple doc. There is not any example.
Does anyone know how to do it and put an example (Objective C)?
You need to override preferredFocusedView, and when you are hiding one view and showing there call this method setNeedsFocusUpdate, your preferredFocusedView implementation should be something like this
- (UIView *)preferredFocusedView
{
// Add your logic here, it could be more complicated then what is below
if (view1.hidden)
{
return _button;
}
else
{
return _button2
}
}
And if you want to make custom view get focus, override canBecomeFocused method and return true
Edit
You can use add a breakpoint and execute this command po [buttonYouWantToFocus _whyIsThisViewNotFocusable] it will tell you why its not focusable.
If you are adding a sub view programmatically, maybe this is what you want:
- (UIView *)preferredFocusedView {
return [view1 preferredFocusedView];
}
I realize your question is specific to Objective-C but here is a way to solve for this in Swift. You need to override the preferredFocusedView property.
override var preferredFocusedView: UIView? {
guard primaryView.hidden == false else {
return secondaryView
}
return primaryView
}
Then just call setNeedsFocusUpdate() whenever an event happens that causes your views to be hidden. Hope this helps...
Another option (if you don't want to use preferredFocusedView) is, instead of setting your view to be hidden, simply remove it from it's superview, like so:
myView.removeFromSuperview()
This automatically takes the focus away from the button that is removed and gives it to another one that is still on screen.
I would like to mimic the Finder's predicatesList. Especially the LeftExpressions popup with its "other" (in German: "Andere...") menu entry and like to popup a NSSheet with a user selectable list of search predicates.
My approach was to create some NSPredicateEditorRowTemplates and one last custom rowTemplate with a leftExpression named "other...".
Then I override the templateViews method and added a separatorItem:
-(NSArray *)templateViews{
NSMutableArray * views = [[super templateViews] mutableCopy];
// I tried already to add here my custom menu entry, but if I add more templates my custom entry (and the separator line) is not fixed at the last index.
if (!isCustomMenuItemAdded) {
NSPopUpButton *leftButton = views[0];
// Add a menu separator
[[leftButton menu]insertItem:[NSMenuItem separatorItem] atIndex:[leftButton menu].itemArray.count-1];
}
return views;
}
My custom predicateEditor is now shown correctly, But if I click on the last menu item 'Other.." the dummy NSPredicateRowTemplate shows up.
I tried to override the -(id)copy method in my rowTemplate class to suppress the new line but that feels strange to me.
-(id)copy{
return nil; // OK, now there is no new row, but this throws an internal exception
}
My question is:
Is there a better way to add a custom menu entry in the left expressions popupButton?
and
How can I suppress that a new predicateTemplateRow is shown in the PredicateEditor?
I want to be able to accept drops on my app's dock icon from files, URLs, and text. Since files (public.file-url) are a subtype of URL (public.url), I added just two Services entries to my Info.plist:
Services
Item 0 (processURL)
Instance method Name = processURL
Send Types
Item 0 = public.url
Menu
Menu item title = Process URL
Item 1 (processString)
Instance method Name = processString
Send Types
Item 0 = public.plain-text
Menu
Menu item title = Process Text
Then I made my -applicationDidFinishLaunching call [NSApp setServicesProvider: self], and wrote a couple methods (-processString:userData:error and -processURL:userData:error) there in my application delegate. The app icon now accepts drops of all three types. In the -processURL:... method, it's easy to check if it's a local file or not, so that handles both of those cases.
One case still eludes me, though. When I try dragging a window's proxy icon to the app, it highlights the icon as if it can accept the drop, but then my method isn't called.
I tried dropping proxy icons from Xcode, Terminal, Preview, and some third-party apps: none would call my services method. But strangely, a proxy icon dropped from the Finder worked fine.
I tried changing public.url to public.item (the base type of the physical hierarchy), but my method is still not called for non-Finder proxy icons.
When the Finder successfully drops a proxy icon on my app, the pboard -types it provides are:
"public.file-url",
"CorePasteboardFlavorType 0x6675726C",
"dyn.ah62d4rv4gu8y6y4grf0gn5xbrzw1gydcr7u1e3cytf2gn",
NSFilenamesPboardType,
"dyn.ah62d4rv4gu8yc6durvwwaznwmuuha2pxsvw0e55bsmwca7d3sbwu",
"Apple URL pasteboard type"
I tried using each of these directly as the "Send Types". "public.file-url" and "NSFilenamesPboardType" highlight the icon as if it'll accept the drop, but don't. The others, unsurprisingly, don't even highlight the dock icon.
I can't find any reference to proxy icons having a different UTI than normal files. Do they? That would be weird.
I know this must be possible, because I can drag proxy icons from any window onto a Terminal window. What am I missing?
UPDATE: From an NSView, if I -registerForDraggedTypes including "public.url", I do get drops of proxy icons from all apps, with exactly the same -types list as from the Finder, listed above. So it's clearly something special to receiving drops via the dock icon. This should still be possible somehow: you can drag a proxy icon from a (non-Finder) window (e.g., an .xcworkspace from Xcode) onto the Terminal dock window, and it catches that just fine.
Swift 4 for your app delegate
func application(_ sender: NSApplication, openFile: String) -> Bool {
Swift.print("sender \(sender) file \(openFile)")
return true
}
func application(_ sender: NSApplication, openFiles: [String]) {
Swift.print("sender \(sender) list \(openFiles)")
// Create a FileManager instance
let fileManager = FileManager.default
for path in openFiles {
do {
let files = try fileManager.contentsOfDirectory(atPath: path)
for file in files {
_ = self.application(sender, openFile: file)// void return
}
}
catch let error as NSError {
print("Yoink \(error.localizedDescription)")
}
}
}
If you implement dragging files to your dock icon using application:openFile: in your NSApplicationDelegate, then dragging proxy icons should work too. The trick to accepting all files is adding a Document Type with extensions of '*'.
I'm currently struggling to use UI elements in Interface Builder. I keep trying to do things "in the .NET way."
I have several buttons that all map down their TOUCH event to the SAME FUNCTION:
-(IBAction) onTouch:(id) sender
{
// do something with touch, DEPENDING ON WHAT BUTTON WAS PUSHED
// I want to do something like
if( sender.tag == "something" )
{
//...doesn't work on apple, of course..
}
}
I want to uniquely identify each BUTTON USING SOMETHING like the TAG property in .NET. I tried using the INTERFACE BUILDER "NAME" field that is on the "Identity" panel of interface builder, but I don't know how to access that field programmatically.
-(IBAction) onTouch:(id) sender
{
// do something with touch, DEPENDING ON WHAT BUTTON WAS PUSHED
// I want to do something like
if( sender.InterfaceBuilderName == "something" )
{
//...doesn't work..
}
}
So, WHAT / IS THERE a way to uniquely identify a UI element (such as a button) OTHER THAN doing something like
-(IBAction) onTouch:(id) sender
{
// look at
[sender currentTitle]
}
The reason that's bad is because if the text on the button changes for some cosmetic reason you break the whole app, right
The last solution I can think of is write seperate functions for each button's touch event but I really want to know if it is possible to uniquely identify a button by something similar to .Net's TAG property.
In the iPhone SDK all UIView objects have a property also called tag which is an integer value and can basically be used to do what you are intending.
I usually define a constant for the tag values I'm going to use for a specific purpose.
You can access the tag on the button object:
myButton.tag = MYBUTTON_TAG_CONSTANT
// button tag constant
#define MYBUTTON_TAG_CONSTANT 1
For buttons, there is a Tag entry in the View section (click on your button, select Attributes Inspector from the Tools menu). You can then use this integer value in your code.
Here is a link that may help as well:
http://www.iphonedevsdk.com/forum/iphone-sdk-development/25582-using-tags-interface-builder.html
UIView's tag property is accessible from Interface Builder. Unlike .NET, it's an integer rather than a string.