I need to display informative message box in Cocoa Application, which control should i use,
i read the document of NSAlert, but it seems, it will create the modal message box, where i need something, where i will just show a popup for fraction of seconds and will get destroyed after some time by it self.
Sounds like a job for Growl.
It's a third-party software product, for which we provide a framework you can include in your application. See also the application-developer page.
you could use the NSTimer for auto dismiss.
[self showMyMessage];//put your code in showMyMessage method to show your alert,
NSTimer* myTimer = [NSTimer scheduledTimerWithTimeInterval:60.0 target:self
selector:#selector(callToDismissAlert:) userInfo:nil repeats:NO];
After 60.0 second , iOS will call the below function
-(void) callToDismissAlert:(NSTimer*) t
{
[self dismissMyAlert];// put your code in dismissMyAlert method to dismiss your alert,
}
Related
I am using xcode and am having a problem moving a button automatically. I have this function that whenever I call it, I expect the button to move to the coordinates that I set:
[movebutton setCenter:CGPointMake(164,50)];
Previously I tried to set an NStimer in an IBAction function and then use the timer to call this movebutton function - the button moved but if I call the same function without an NStimer it no longer works.
The code for the timer is:
[NSTimer scheduledTimerWithTimeInterval:(0.1/3) target:self selector:#selector(movebutton:) userInfo:nil repeats:YES];
Can anyone spot what I am missing?
Update:
I try to print out the x and y coordinates of the button and actually the button position has been updated.
NSLog(#"x position %f",movebutton.frame.origin.x);
however, on the UI screen it does not reflect at all.
Try placing
[self.view layoutIfNeeded];
in your moveButton: method so that when it's called from the timer it knows to update the UI.
Where do you call -[UIButton setCenter] manually? Couldn't comment because I don't have permission to comment.
The NSTimer works because it fires the method every 0.1/3 because the NSTimer instance is added to run loop
If I start an NSTimer like this:
#property (strong) NSTimer * messageTimer;
self.messageTimer = [NSTimer scheduledTimerWithTimeInterval:10.0
target:self
selector:#selector(checkForMessages)
userInfo:nil
repeats:YES];
Does it continue to run when I switch to different view controllers?
Until I cancel it with:
[messageTimer invalidate]; self. messageTimer = nil;
Yes.
Okay, now here is an extended description. NSTimer registers itself on nearest NSRunLoop, that is, current dispatch loop (they may nest). This loop asks various sources for events and calls corresponding callbacks.
When it is time for NSTimer to fire, it returns YES to NSRunLoop and that runs passed callback. There is no such thing as "other current view controller". It is all about first responder and view hierarchy, neither doesn't have any effect on run loops.
How to make a small drop-down window on the right side of the screen. Which show window for example for 1 second and go back, out of the screen
What method i must use?
or if it can, how make it in interface builder?
for creating drop down refer to this link and for making it disappear you can use an NSTimer for 1 second
NSTimer *aTimer = [NSTimer scheduledTimerWithTimeInterval:1.0
target:self
selector:#selector(timerFired:)
userInfo:nil
repeats:NO];
}
-(void)timerFired:(NSTimer *) theTimer
{
["your drop down view" removeFromSuperview];
}
I'm relativly new to this so please bear with me.
I need to know how to loop a sound (or any object for that matter) at a definable interval.
Something simple like, touch a button and a small sound file plays every x seconds until you touch another button or touch the same button again.
NSTimer is what you're looking for to perform an action at specific time intervals.
Creating a simple timer to perform some action every 5 seconds would look something like this:
//This will start a repeating timer that will fire every 5 seconds
-(IBAction)startTimer {
self.timer = [NSTimer scheduledTimerWithTimeInterval:5.0
target:self
selector:#selector(someAction:)
userInfo:nil
repeats:YES];
}
//The method the timer will call when fired
-(void)someAction:(NSTimer *)aTimer {
//Do stuff here
}
-(IBAction)stopTimer {
[self.timer invalidate];
}
As far as playing sounds go, iOS provides a lot of options. Fortunately Apple has provided plenty of good documentation on the different options available to you, how to choose the right one, and implement it.
[Cocoa/Objective-C]
I adapted a timer routine (for current time) from this site (and it works great - thanks). It's currently attached to a button.
My question is: How do I make it start when my app starts up (and not use a button) (in other languages, I'd simply put the action listener or timer in the Form)...?
Thank for any help on this!
In your application delegate you'll find a method called
- (void)applicationDidFinishLaunching:(UIApplication *)application
I guess that would be where to start a timer on app startup.
Put it in your awakeFromNib method. This is called on all objects that get deserialized from your nib (like your application delegate), but it isn't called until all objects are deserialized and wired (so you can use your text field, for instance). For example:
- (void)timerFired:(NSTimer*)timer
{
NSLog(#"Timer completed!");
}
- (void)awakeFromNib
{
[NSTimer scheduledTimerWithTimeInterval:30.0 target:self selector:#selector(timerFired:) userInfo:nil repeats:NO];
}
Obviously, in this simple example the timer could have been created in either the applicationDidFinishLaunching: method or the awakeFromNib method since it doesn't interact with any other serialized objects, but in your case, it sounds like you need the awakeFromNib method.