How to put an UIWebView inside UIAlertView? - iphone

I've tried to add a WebView to the AlertView using this code:
- (void)viewDidLoad {
search = [[UIAlertView alloc] initWithTitle:#"title" message:#"iGoogle" delegate:nil cancelButtonTitle:#"Cancel" otherButtonTitles:#"Search", nil];
[search addSubview:googleView];
googleView = [[UIWebView alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
[search show];
[search release];
[super viewDidLoad]; }
Still, only the AlertView shows up, without the WebView. And also, where can I get more details on adding stuff like CGRectMakes?

try to add [search addSubview:googleView]; after the googlview is allocated...

Did you try to interchange addSubview:googleView call string with googleView = string?

Here's a link to something I used a while back to add a subview to a UIAlertView. The "trick" is adding a message param that makes the alert view increase in height, then you place a subview on top of that. I've never tried it with a web view.
http://www.iphonedevsdk.com/forum/iphone-sdk-development/1704-uitextfield-inside-uialertview.html
Also make your you init your webview with a url and implement delegate as necessary.

Try this
- (void)viewDidLoad
{
googleView = [[UIWebView alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
search = [[UIAlertView alloc] initWithTitle:#"title" message:#"iGoogle" delegate:nil cancelButtonTitle:#"Cancel" otherButtonTitles:#"Search", nil];
[search addSubview:googleView];
[search show];
[search release];
[super viewDidLoad];
}
Initialize the memory for the webview first and then add it inside the alert view.

UIAlertView is deprecated in iOS 8.
To get the same thing implemented use UIAlertController.
NSURL *url = [[NSBundle mainBundle] URLForResource:#"page" withExtension:#"html"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
UIAlertController *alert = [UIAlertController alertControllerWithTitle:#"HTML" message:nil preferredStyle:UIAlertControllerStyleAlert];
webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 60, 60)];
webView.backgroundColor = [UIColor clearColor];
[alert.view addSubview:webView];
[self presentViewController:alert animated:YES completion:nil];

Related

Alert View show me warning

When I use alertView using below code, it shows me the warning
warning: Semantic Issue: Method '-addTextFieldWithValue:label:' not found (return type defaults to 'id')
Here is the code:
UIAlertView *alSave=[[UIAlertView alloc]initWithTitle:#"Save as" message:#"Title the note and click Save" delegate:self cancelButtonTitle:#"save" otherButtonTitles:#"cancel", nil];
NSArray *arr=[noteObj.noteTitle componentsSeparatedByString:#" - "];
app.longClickId = [noteObj.noteId integerValue];
[alSave addTextFieldWithValue:[NSString stringWithFormat:#"%#",[arr objectAtIndex:0]] label:#"Note Name"];
// show me warning at this place
textField = [alSave textFieldAtIndex:0];
textField.keyboardType = UIKeyboardTypeAlphabet;
textField.keyboardAppearance = UIKeyboardAppearanceAlert;
textField.autocorrectionType = UITextAutocorrectionTypeNo; // correction automatically
[alSave show];
if (app.NotePopOver!= nil) {
[app.NotePopOver dismissPopoverAnimated:YES];
}
[alSave release];
If you use a private method (of which addTextFieldWithValue: is one), then Apple will most likely reject your app. You can achieve the same result with the following snippet, courtesy of this answer which credits a no longer working link:
UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:#"Your title here!" message:#"this gets covered" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"OK", nil];
UITextField *myTextField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
[myTextField setBackgroundColor:[UIColor whiteColor]];
[myAlertView addSubview:myTextField];
CGAffineTransform myTransform = CGAffineTransformMakeTranslation(0.0, 130.0);
[myAlertView setTransform:myTransform];
[myAlertView show];
[myAlertView release];
That method is undocumented. You will have to create your own text field and then add it to the alert view.

progressbar in UIAlertview issue while parsing

I want to resign UIAlertView containing activity indicator. I am putting following code. It is working while loading data but the UIalertview is not resigning after successful parsing. What condition should I give here???
- (void) updateFilterProgress{
NSAutoreleasePool *pool = [NSAutoreleasePool new];
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:#"Loading..." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] autorelease];
[alert show];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
// Adjust the indicator so it is up a few pixels from the bottom of the alert
indicator.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height - 50);
[indicator startAnimating];
[alert addSubview:indicator];
[indicator release];
[pool release];
}
ON my button click event I put following code
// **EDIT==1**
[NSThread detachNewThreadSelector:#selector(updateFilterProgress) toTarget:self withObject:nil];toTarget:self withObject:nil]; //for calling updateFilterProgress
NSString *url = [NSString stringWithFormat:#"http://....url...../hespdirectory/phpsqlsearch_genxml.php?lat=%f&radius=%f&lng=%f",lati,longi,radius];
//NSLog(#"NSString *url");
NSLog(#"%#", url);
//NSString *escapedUrl = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]
NSURL *URL = [NSURL URLWithString:url];
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:URL];
//Initialize the delegate.
XMLParser *parser = [[XMLParser alloc] initXMLParser];
//Set delegate
[xmlParser setDelegate:parser];
//Start parsing the XML file.
BOOL success = [xmlParser parse];
if(success)
{ **//EDIT==2**
[alert dismissWithClickedButtonIndex:0 animated:YES]; //for resigning alertview
for (int i = 0; i < [appDelegate.markers count]; i++)
{
//marker *aMarker = [[marker alloc] init];
marker *aMarker = [appDelegate.markers objectAtIndex:i];
location.latitude = [aMarker.lat floatValue];
location.longitude =[aMarker.lng floatValue];
AddressAnnotation *annobj = [[AddressAnnotation alloc] initWithCoordinate:location];
annobj.title = aMarker.name;
[mapView addAnnotation:annobj];
[annobj release];
}
}
I want to resign this UIAlertView containing activity indicator.......
Set your UIAlertView and ActivityIndicator (and all objects inside the alert view) as members of your class file.
Then, where you'd normally release these items (and where you want to dismiss the alert) you can call this:
[myAlertView dismissWithClickedButtonIndex:0 animated:YES];
This has the same effect as if though the user clicked the cancel button on it, which is perfectly acceptable.
Hope this helps!

How to prompt user for text input in Alert view

I am writing a section of code where it would be best if I could use a pop up box something like UIAlertView and prompt the user to enter text like a password.
Any pointers on an elegant way of doing this?
Things are much simpler in iOS 5, just set the alertViewStyle property to the appropriate style (UIAlertViewStyleSecureTextInput, UIAlertViewStylePlainTextInput, or UIAlertViewStyleLoginAndPasswordInput). Example:
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Password" message:#"Enter your password:" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Ok", nil];
alertView.alertViewStyle = UIAlertViewStyleSecureTextInput;
UITextField *passwordTextField = [alertView textFieldAtIndex:0];
[alertView show];
> Simple You can apply like this
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Filename" message:#"Enter the file name:" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Ok", nil];
alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
UITextField *passwordTextField = [alertView textFieldAtIndex:0];
[alertView show]
The best way that I've found to do this is to follow this tutorial: http://junecloud.com/journal/code/displaying-a-password-or-text-entry-prompt-on-the-iphone.html
The code used to achieve this is (taken directly from that great tutorial):
UIAlertView *passwordAlert = [[UIAlertView alloc] initWithTitle:#"Server Password" message:#"\n\n\n"
delegate:self cancelButtonTitle:NSLocalizedString(#"Cancel",nil) otherButtonTitles:NSLocalizedString(#"OK",nil), nil];
UILabel *passwordLabel = [[UILabel alloc] initWithFrame:CGRectMake(12,40,260,25)];
passwordLabel.font = [UIFont systemFontOfSize:16];
passwordLabel.textColor = [UIColor whiteColor];
passwordLabel.backgroundColor = [UIColor clearColor];
passwordLabel.shadowColor = [UIColor blackColor];
passwordLabel.shadowOffset = CGSizeMake(0,-1);
passwordLabel.textAlignment = UITextAlignmentCenter;
passwordLabel.text = #"Account Name";
[passwordAlert addSubview:passwordLabel];
UIImageView *passwordImage = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"passwordfield" ofType:#"png"]]];
passwordImage.frame = CGRectMake(11,79,262,31);
[passwordAlert addSubview:passwordImage];
UITextField *passwordField = [[UITextField alloc] initWithFrame:CGRectMake(16,83,252,25)];
passwordField.font = [UIFont systemFontOfSize:18];
passwordField.backgroundColor = [UIColor whiteColor];
passwordField.secureTextEntry = YES;
passwordField.keyboardAppearance = UIKeyboardAppearanceAlert;
passwordField.delegate = self;
[passwordField becomeFirstResponder];
[passwordAlert addSubview:passwordField];
[passwordAlert setTransform:CGAffineTransformMakeTranslation(0,109)];
[passwordAlert show];
[passwordAlert release];
[passwordField release];
[passwordImage release];
[passwordLabel release];
If my app was not to be released for yet a months or two, then I would login to http://developer.apple.com, look at the iOS 5 beta area, and see if UIAlertView might have something in store for us.
I think it would be helpful to know that UIAlertView is not modal so the alert will not block.
I ran into this problem where I wanted to prompt the user for input then continue and then use that input in the code after. But instead the code after the [alert show] would run first until you reached the end of the run loop then the alert would display.
Optimized code:
UIAlertView *passwordAlert = [[UIAlertView alloc] initWithTitle:#"Password"
message:#"Please enter the password:\n\n\n"
delegate:self
cancelButtonTitle:NSLocalizedString(#"Cancel",nil)
otherButtonTitles:NSLocalizedString(#"OK",nil), nil];
UITextField *passwordField = [[UITextField alloc] initWithFrame:CGRectMake(16,83,252,25)];
passwordField.borderStyle = UITextBorderStyleRoundedRect;
passwordField.secureTextEntry = YES;
passwordField.keyboardAppearance = UIKeyboardAppearanceAlert;
passwordField.delegate = self;
[passwordField becomeFirstResponder];
[passwordAlert addSubview:passwordField];
[passwordAlert show];
[passwordAlert release];
[passwordField release];

how can I change appearance of alert from UINotification?

is there any way to change the outlook(appearance shape) of UINotification Alert, like I can insert image on UIAlertView, as below
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Status Update" message:myString delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 30, 100, 100)];
NSString *path = [[NSString alloc] initWithString:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:#"reminder_logo.png"]];
UIImage *bkgImg = [[UIImage alloc] initWithContentsOfFile:path];
[imageView setImage:bkgImg];
[bkgImg release];
[path release];
[alert addSubview:imageView];
[imageView release];
[alert show];
[alert release];
This code will show an image on UIAlertView. I want same thing for UINotification, but apple should accept it, because I can't alter their libraries, else rejection will happen from app store.
Local notifications are created and displayed by the system, not your app. Therefore you have no control over how they are presented.

How to use UIWebview inside UIAlertView in iphone

I am trying to insert UIWebview in UIAlertview as I this tutorial did http://codesofa.com/blog/archive/category/iphone with Table, i have tried webview in code but facing exception and my program in terminationg due to it.
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Alert" message:#"WebView" delegate:nil cancelButtonTitle:nil otherButtonTitles:#"Ok", nil];
UIWebView *webView = [[UIWebView alloc] init];
[webViewn setFrame:CGRectMake(0,0,80,50)];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"google.com"]]];
[alert addSubview:webView];
[webView release];
[alert show];
[alert release];
try like this.