how can i show multiple messages in my alertView from different variables?
Build the desired NSString from your multiple variables, e.g.:
NSString *foo;
NSString *bar;
NSString *baz;
// ... set values for foo, bar and baz ...
NSString *myMessage = [NSString stringWithFormat:#"%# %# %#", foo, bar, baz];
Then set your alert view to use the composite message myMessage:
NSString *myTitle = #"xyz";
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: myTitle
message: myMessage
delegate: nil
cancelButtonTitle: #"OK"
otherButtonTitles: nil];
[alert show];
[alert release];
NSString *string1=#"total time played:30\n";
NSString *string2=#"total score :90\n";
NSString *string3=#"19/2/20010 12:00:77\n";
NSString *string=[NSString stringWithFormat:#"%#%#%#",string1,string2,string3];
UIAlertView *progressAlert = [[UIAlertView alloc] initWithTitle:#"Hello" message:string delegate:nil cancelButtonTitle:#"ok" otherButtonTitles:nil];
[progressAlert show];
[progressAlert release];
NSString *str1=#"Message 1.";
NSString *str2= #"Message 2.";
NSString *str3 = #"Message 3";
NSString *msg=[NSString stringWithFormat:#"%#\n%#\n%#",str1,str2,str3];
FreeCoinsCustomAlert* alert = [[FreeCoinsCustomAlert alloc] initWithTitle:msg
message:nil delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
You may wish to flesh out your question a bit more, but working from my understanding of your question, you should just be able to use the
- (id)initWithTitle:(NSString *)title message:(NSString *)message delegate:(id)delegate cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, ...
UIAlertView constructor. Then just concatenate your variables into a single NSString object and pass it as the (NSString*)message. The
+ (id)stringWithFormat:(NSString *)format, ...
factory method makes this trivial. I would recommend reading your options with NSString in the Apple documentation.
Related
In my picker view i have a "Custom" option which should popup a UIAlertView for the user to enter a new value, the value is saved in the plist source of the picker for future reference. xxxEditingDidBegin is being called repeatedly (never ending).
I presume its because my UIAlertView is triggering the picker to close.
How should I have done this?
- (IBAction)serviceTypeFieldEditingDidEnd:(UITextField *)sender
{
UIPickerView *picker = [sender.inputView.subviews objectAtIndex:0];
NSString *selText = [serviceTypeArray objectAtIndex: [picker selectedRowInComponent:0]];
sender.text = selText;
if (NSOrderedSame==[selText compare:#"Custom"])
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Custom Role"
message:#"Enter Role Title"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Ok", nil];
alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
[alertView show];
}
}
Implement method like
- (IBAction)doSelectDate:(UIDatePicker *)sender
{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:#"Hi" message:#"AlertView is shwoing" delegate:nil cancelButtonTitle:#"Dismiss" otherButtonTitles:nil, nil];
[alert show];
[alert release];
}
and connect above method with ValueChanged Event of UIPickerView;
I fixed it like this
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
inComponent:(NSInteger)component
{
NSString *rowString = [serviceTypeArray objectAtIndex:row];
if ([rowString compare:#"Custom"] == NSOrderedSame)
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Custom Role"
message:#"Enter Role Title"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Ok", nil];
alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
[alertView show];
}
else
{
_serviceType.text = rowString;
}
}
my app needs alert msg and if yes button pressed then one more alert msg and then i have to called a method.This is my code:
-(IBAction)resetPressed:(id)sender
{
NSString *title= [NSString stringWithFormat:#"Warning"];
NSString *message = [NSString stringWithFormat:#"Are you sure you want to Reset"];
NSString *ok = [NSString stringWithFormat:#"No"];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
message:message
delegate:self
cancelButtonTitle:ok otherButtonTitles:#"Yes",nil];
[alert show];
[alert release];
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (alertView.tag ==1)
{
NSString *title= [NSString stringWithFormat:#"Warning"];
NSString *message = [NSString stringWithFormat:#"Are you sure you want to Reset"];
NSString *ok = [NSString stringWithFormat:#"No"];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
message:message
delegate:self
cancelButtonTitle:ok otherButtonTitles:#"Yes",nil];
alert.tag =2;
[alert show];
[alert release];
}
else if(alertView.tag ==2)
{
[self resetArray];
}
}
Thanks.
I'm not sure what your goal is but a few things look wrong to me anyways:
First of all you should create your strings this way:
NSString *title= #"Warning";
There's no need to use stringWithFormat in your case.
Then, it doesn't seem you properly set the first UIAlert's tag to 1, and the default value for tags is 0 so I guess the if statements in didDismissWithButtonIndex are never true.
Also, you should check which button was pressed using buttonIndex, otherwise you are going to show both alert and call [self resetArray] whichever button is pressed by the user.
Hope that helps.
In your code, you create the first alert, but never actually set the tag on it. You should do:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
message:message
delegate:self
cancelButtonTitle:ok otherButtonTitles:#"Yes",nil];
alert.tag = 1; //Or 2, or something.
[alert show];
[alert release];
Then the code in your delegate method will run.
Please define two separate UIAlertView in .h file
#interface XYZViewController:UIViewController
{
UIAlertView *firstAlertView;
UIAlertView *secondAlertView;
}
Now in your .m file modify as below:
-(IBAction)resetPressed:(id)sender
{
NSString *title= [NSString stringWithFormat:#"Warning"];
NSString *message = [NSString stringWithFormat:#"Are you sure you want to Reset"];
NSString *ok = [NSString stringWithFormat:#"No"];
if(firstAlertView == nil)
{
firstAlertView = [[UIAlertView alloc] initWithTitle:title message:message delegate:self cancelButtonTitle:ok otherButtonTitles:#"Yes",nil];
}
[firstAlertView show];
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (alertView == firstAlertView)
{
NSString *title= [NSString stringWithFormat:#"Warning"];
NSString *message = [NSString stringWithFormat:#"Are you sure you want to Reset"];
NSString *ok = [NSString stringWithFormat:#"No"];
if(secondAlertView == nil)
{
secondAlertView = [[UIAlertView alloc] initWithTitle:title message:message delegate:self cancelButtonTitle:ok otherButtonTitles:#"Yes",nil];
}
[secondAlertView show];
}
else if(alertView == secondAlertView)
{
[self resetArray];
}
}
and in dealloc method please release the allocated UIAlertviews.
Hope i am clear to you.
Thanks,
Jim.
i want simply to show a double value on a uialert view it is possible?
Put the value into a formatted NSString and send that to the alertView:
NSString *messageString = [NSString stringWithFormat:"#number = %.2f", 42.0];
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:#"Title text" message:messageString delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
[alertView release];
How are you showing the UIAlertView now? Something like the following should work:
double myDouble = 12.6;
NSString *alertString = [NSString stringWithFormat:#"%g", myDouble];
UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:alertString
message:nil
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:nil];
[myAlert show];
I am creating an iphone application in which I have to upload photos using different services.
I am successful in uploading photos with Twitpic & YFrog but not able to do with Plixi.
I am using Oauth ,as Twitter is not allowing Basic authentication.
If anyone has tried with Plixi ,please help me out!!
I have googled a lot but not getting any relevant documentation for the new Oauth for Plixi.
Finally, I am with a solution for my problem :)
If anyone is also stuck with this problem, just add the TweetPhoto folder from the following application link:
http://code.google.com/p/tweetphoto-api-objective-c/downloads/detail?name=TPAPI-Objective-C-Library.zip
Change the tweetphoto urls for plixi now.
Also, can refer to my following code for making function calls:
-(void)uploadtoTweetPhoto{
NSString *message = [self.tweetTextView.text stringByReplacingOccurrencesOfString:#"Max. 140 characters" withString:#""];
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc]init];
if((message == nil) || ([message isEqual:#""])){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: #"Please enter your tweet message.." message: #"" delegate:nil cancelButtonTitle: #"Ok" otherButtonTitles: nil];
[alert show];
[alert release];
}
else{
[dictionary setObject:message forKey:#"message"];
}
if([dictionary count] == 1){
[indicator startAnimating];
[NSThread detachNewThreadSelector:#selector(uploadPhotoToTweetPhoto:) toTarget:self withObject:dictionary];
}
[dictionary release];
}
- (void)uploadPhotoToTweetPhoto:(NSDictionary *)dictionary{
NSString *message = [dictionary objectForKey:#"message"];
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *accessTokenKey = [[NSUserDefaults standardUserDefaults] valueForKey:#"oauth_token"];
NSString *accessTokenSecret = [[NSUserDefaults standardUserDefaults] valueForKey:#"oauth_token_secret"];
TweetPhoto *tweetPhoto = [[TweetPhoto alloc] initWithSetup:accessTokenKey identitySecret:accessTokenSecret apiKey:Plixi_API_Key serviceName:#"Twitter" isoAuth:YES];
NSData *dat =[tweetPhoto upload:UIImageJPEGRepresentation(self.imgView.image,0.8) comment:message tags:#"" latitude:23.4646 longitude:-87.7809 returnType:TweetPhotoCommentReturnTypeXML];
NSString *status =[NSString stringWithFormat:#"%i",[tweetPhoto statusCode]];
[tweetPhoto release];
[self performSelectorOnMainThread:#selector(photoUploadedtoTweetPhoto:) withObject:status waitUntilDone:[NSThread isMainThread]];
[pool release];
}
- (void)photoUploadedtoTweetPhoto:(NSString*)status{
[indicator stopAnimating];
if([status isEqualToString:#"201"])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: #"Tweet Posted" message: #"" delegate:nil cancelButtonTitle: #"Ok" otherButtonTitles: nil];
[alert show];
[alert release];
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: #"Tweet Failed" message: #"" delegate:nil cancelButtonTitle: #"Ok" otherButtonTitles: nil];
[alert show];
[alert release];
}
}
I'm curious as to the phrase you used in Google. In any case, googling "plixi api" tool me to this page, which links to a Cocoa wrapper on Google Code.
I am trying to load names in an array using UIAlert and then print them one by one. I am not able to figure this out, can anyone help me out with this? I would really appreciate your help.
NSArray *array = [NSArray arrayWithObjects:#"One", #"Two", #"Three", #"Four", nil];
for (NSString *element in array)
{
// Log to console..
NSLog(#"element: %#", element);
//Show in alert.. Really??
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"ALERT TITLE" message:element delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
NSArray *array = [NSArray arrayWithObjects:#"One",#"Two",#"Three",nil];
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"ALERT TITLE" message:nil delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
for(NSInteger index=0; index<[array count]; index++)
{
[alert addButtonWithTitle:[array objectAtIndex:index]];
}