Cocoa Touch - Dialogue boxes? - iphone

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.

Related

Exc_Bad_Access in alertview show

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.

Close Alert View Via Code

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..

UIAlertView after completion of NSLog

I am new to iphone..
Actually i wanted to know is it possible to put an UIAlertView after the completion of NSLog as i wanted to check whether the statement really works or not as i cant check NSLog in the iphone.
Please suggest me whether it is possible and how?
NSLog will still work on iPhone..
You can only see it in the console if you have attached the device to your mac..and then use the app.
Anyways.
You can show your AlertView after log like this.( This Nslog is an example..replace with what is your actual log)
NSLog(#" Image Loaded");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Log" message:#"Image Loaded" delegate:nil cancelButtonTitle:#"Okay" otherButtonTitles:nil, nil];
[alert show];
[alert release];
If the NSLog statement works, it'll show up in the XCode console. So if you debug the app on your phone via XCode, you should see the NSLog. Or did you have something else on your mind ?

iPhone - a UI component that looks like an Alert box - Beginner

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.

Best Practices for implementing a modal Alert View using Cocoa Touch?

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.