Does anyone have any best practices, tips & tricks, or recommendations for how to create modal Alert Views with Cocoa Touch?
I like to think there is a way to make this difficult task trivial or at least easier.
You can use something like this:
void AlertWithMessage(NSString *message)
{
/* open an alert with an OK button */
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Name of the Application"
message:message
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles: nil];
[alert show];
[alert release];
}
I just use UIAlertView to display modal alerts. What additional functionality are you looking for?
Check out the UICatalog sample code from Apple. It shows the usage of both Alerts and Sheets on the phone.
Related
Getting Exc_Bad_Access in UIAlertView show message.
UIAlertView *systemAlert1 = [[UIAlertView alloc]initWithTitle:#"System message" message:#"note" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[systemAlert1 show]; **//Crashing on this line [EXC_BAD_ACCESS]**
[systemAlert1 release];
Why i am getting this?? Please help
ANY UI stuff including the showing of alerts should be done on Main thread.
If you are doing this on some other thread, it will definitely crash.
It may be because your alert gets invoked from your background thread and not the main thread. It is recommended that user interface related changes should only be made on Main Thread to avoid this kind of behaviors of the application
Try this code:
UIAlertView *systemAlert1 = [[UIAlertView alloc]initWithTitle:#"System message" message:#"note" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[systemAlert1 performSelectorOnMainThread:#selector(show) withObject:nil waitUntilDone:YES];
[systemAlert1 release];
Hope this helps. Let me know if you need anything else.
I've got an alert:
UIAlertView *connectionError = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Connection Failed" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
I want to know how I can programatically close an alert view when I hit a certain event in my code. I know there is no distinct call to just close out an alert, and I've seen people make calls straight to buttons, however, I'm not sure how to call the cancel button on an alert.
Is this even the right way to go about it? Or is there a better path?
You can use -dismissWithClickedButtonIndex:animated: method for dismissing alert view:
[connectionError dismissWithClickedButtonIndex: connectionError.cancelButtonIndex
animated: YES];
That's the only public API for dismissing alerts, so you should use it.
Declare you alert view in .h file
then call this function
[connectionError dismissWithClickedButtonIndex:0 animated:YES];
Hope it helps..
I would like to know how to make a basic "Hello, World!" MobileSubstrate tweak.
Getting Started will help you setup the environment for developing. This IPF will help you understand building your tweak/app, and you can look at my github for code examples.
I wrote an answer in another thread which apparently was pretty much liked by some people; have a look at it here.
Still, #EvilPenguin's answer is entirely right, mine just explains a couple of things here and there, but it ends up redirecting you to the same place.
#import <SpringBoard/SpringBoard.h> // for SBScreenFlash
%hook SBAwayLockBar
-(void)unlock // the method you’re hooking
{
%orig;
[[%c(SBScreenFlash) sharedInstance] flash];
}
%end
If you unlock your Device using the Slider it'll screenshot your Screen. Its not a good Tweak, but it was all you asked for.
#import <SpringBoard/SpringBoard.h> // for SBScreenFlash
%hook SBAwayLockBar
-(void)unlock // the method you’re hooking
{
%orig;
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Hello World!" message:#"my first Tweak" delegate:nil cancelButtonTitle:#"Cool" otherButtonTitles:nil];
[alert show];
[alert release];
}
%end
This will prompt an alertview to you saying hello world ;)
Have fun
I need to know what this UI component is called ? It looks like an Alert but has textfeilds and buttons in it ?
1.) What is this UIComponent called ?
2.) Is there any video tutorial which shows how to implement this ? (If so link) or any tutorials that discuss the implementation of this
It's UIAlertView
Here is the tutorial to make custom UIAlertView
That is an Android component, there is no equivalent in iOS.
There is the UIAlertView, but you cannot edit text within it.
http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIAlertView_Class/UIAlertView/UIAlertView.html#//apple_ref/occ/cl/UIAlertView
If you want to be able to let users edit text in the component, you have to create it from scratch, e.g. create a UIView and add a UITextView to it and some UIButtons and create the functionality to display/dismiss the component yourself.
AlertView
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Title"
message:#"Message"
delegate:nil
cancelButtonTitle:#"Cancel"
otherButtonTitles:nil];
[alert show];
[alert release];
The component on iPhone is called a UIAlertView. You can add subviews in it to get text-fields, although this is not recommended by Apple - but you won't get rejected either. In iOS5, there are dedicated UIAlertView types for this. If you are building for iOS5, this is the method you should use.
How can i get a plain basic dialogue box in cocoa touch.seems so simple but I can figure it out...
Thanks!
You want the UIAlertView class. For example:
UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:#"Something happened"
message:#"And here is some more information about what it is."
delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[myAlert show];
[myAlert release];
Create an NS Window using the Interface Builder. In your appdelegate, open the window.
Another option is CFUserNotification. The advantage to UIAlertView is that it does not require you to link against UIKit.