This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
Im trying to find the correct way to get a float value into a UIAlertView. My float value is only used to check another value rather than passed to string somewhere.
I suppose I could set my float value to a label and set it to hidden and pass that to my alert, but im sure this cant be the proper way to do this, some advice would be appreciated
float x = ([_continuityRingFinalR1.text floatValue]); /stringWithFormat:#"%.1f", x * y]]
float y = (1.67);
if ([_continuityRingFinalRn.text floatValue] > x * y ) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Advisory Warning"
message:[NSString stringWithFormat: #"Based on your value of %# this value may not be acceptable. %# would be acceptable",_continuityRingFinalR1.text, ]///<<< my float value here
delegate:self cancelButtonTitle: #"Ignore" otherButtonTitles: #"Retest", nil];
[alert show];
}
%f is used in an NSString for a float/double instead of %#
float x = ([_continuityRingFinalR1.text floatValue]); /stringWithFormat:#"%.1f", x * y]]
float y = (1.67);
float example;
if ([_continuityRingFinalRn.text floatValue] > x * y ) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Advisory Warning"
message:[NSString stringWithFormat: #"Based on your value of %# this value may not be acceptable. %f would be acceptable",_continuityRingFinalR1.text, example];
delegate:self cancelButtonTitle: #"Ignore" otherButtonTitles: #"Retest", nil];
[alert show];
}
Here's a helpful link
I think you want this
message:[NSString stringWithFormat: #"Based on your value of %# this value may not be acceptable. %0.2f would be acceptable",_continuityRingFinalR1.text, x*y ];
//Passing second argument as x*y
Related
I want to insert some values in a table of database.but it is showing (NULL) on insertion
I am using This code
http://pastie.org/10929618
I have used this Link for Reference
http://www.tutorialspoint.com/ios/ios_sqlite_database.htm
//Insert Method
-(void)SaveAction{
BOOL success = NO;
NSString *alertString = #"Data Insertion failed";
success = [[DBManager getSharedInstance]saveData:#"100" username:#"byname" type:#"one2one" user_to:#"144" user_from:#"145" timestamp:#"42015"];
if (success == NO) {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:
alertString message:nil
delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
}
}
You are missing the column value.
// you are passing the value use below method but dnt have "message1" column value
success = [[DBManager getSharedInstance]saveData:#"100" username:#"byname" type:#"one2one" user_to:#"144" user_from:#"145" timestamp:#"42015"];
// compare the below query
NSString *insertSQL = [NSString stringWithFormat:#"insert into chatDetail (chat_id,username, type, message1,user_to,user_from,timestamp) values (\"%ld\",\"%#\", \"%#\", \"%#\",\"%#\",\"%#\")",(long)[chat_id integerValue], username, type, user_to,user_from,timestamp];
So i have an intricate system of if statements all which after evaluating a certain statement, the correct if statement 'activates' and prints something to the label on my view controller. But no matter what data i enter and activate the different if statements all the label prints is either "nan" or "inf" and im not sure why or what is causing this?
code:
if (CurrentPH < 7.2 && CurrentPH >= 6.2) {
float desiredChangePh = 1;
float changeFactorPH = desiredChangePh / CurrentPhPPM;
float chemicalDosagePh = PoolFactorPh * changeFactorPH * CurrentPhPounds;
self.PhChemicalLabel.text = [NSString stringWithFormat:#"%f", chemicalDosagePh];
self.PhUpOrDownLabel.text = #"Ph Increaser";
}
else if (CurrentPH > 7.3 && CurrentPH <= 8.3) {
float DesiredChangePhDecreaser = 1;
float ChangeFactorPhDecreaser = DesiredChangePhDecreaser / CurrentPhDecreaserPPM;
float ChemicalDosagePhDecreaser = PoolFactorPhDecreaser * ChangeFactorPhDecreaser * CurrentPhDecreaserLbs;
self.PhChemicalLabel.text = [NSString stringWithFormat:#"%f", ChemicalDosagePhDecreaser];
self.PhUpOrDownLabel.text = #"Ph Decreaser";
}
else if (CurrentPH < 6.2 && CurrentPH >= 5.2){
float DesiredChangeLowPh = 1;
float ChangeFactorLowPh = DesiredChangeLowPh / CurrentPhPPM;
float ChemicalDosageLowPh = PoolFactorPh * ChangeFactorLowPh * CurrentPhPounds;
self.PhChemicalLabel.text = [NSString stringWithFormat:#"%f", ChemicalDosageLowPh];
self.PhUpOrDownLabel.text = #"Ph Increaser";
}
else if (CurrentPH > 8.3 && CurrentPH <= 9.3){
float DesiredChangHighPH = 1;
float ChangeFactorHighPh = DesiredChangHighPH / CurrentPhDecreaserPPM;
float ChemicalDosageHighPH = PoolFactorPhDecreaser * ChangeFactorHighPh * CurrentPhDecreaserLbs;
self.PhChemicalLabel.text = [NSString stringWithFormat:#"%f",ChemicalDosageHighPH];
self.PhUpOrDownLabel.text = #"Ph Decreaser";
}
else if (CurrentPH > 9.3){
UIAlertView *OpenALertPhHigh = [[UIAlertView alloc] initWithTitle:#"Pool Pal" message:#"Your Ph seems unusually high, check to make sure you entered it correctly or consult the Pool Tips page for further instruction" delegate:nil cancelButtonTitle:#"Okay" otherButtonTitles:nil, nil];
[OpenALertPhHigh show];
}
else if (CurrentPH < 5.2) {
UIAlertView *OpenALertPhLow = [[UIAlertView alloc] initWithTitle:#"Pool Pal" message:#"Your Ph seems unusually low, check to make sure you entered it correctly or consult the Pool Tips page for further instruction" delegate:nil cancelButtonTitle:#"Okay" otherButtonTitles:nil, nil];
[OpenALertPhLow show];
}
else{
self.PhChemicalLabel.text = #"Your Ph is perfect";
NSLog(#"okay");
}
}
This is happening because you're making some kind of math error, such as division by zero or an operation involving a nil object. Make sure CurrentPhPPM and other similar variables used in calculating the labels are initialized properly. Can't provide any other help without knowing more about how those variables are initialized.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
NSMutableArray*array = [[NSMutableArray alloc] initWithObjects:#"a", #"d", #"r", nil];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"msg"
message:[array Description]
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alert show];
Output should be like
a
d
r
Not like
(a
d
r
)
You can directly use NSString for this purpose.
But if you insist on using NSMutableArray then do something like this.
NSMutableArray *arr = [[NSMutableArray alloc] initWithObjects:#"a",#"b",#"c", nil];
NSString *joinedString = [arr componentsJoinedByString:#" "];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"msg"
message:joinedString
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alert show];
You are sending an NSArray description to an NSString parameter. This is where the braces come from. If you send a description message to an array, you will get back a string with all objects in an array enclosed with 'your' braces.
I am not sure what are you actually trying to achieve here. Message should be an NSString object like #"Invalid input".
If you want output a d r, I would combine objects of array into single string:
NSMutableArray*array = [[NSMutableArray alloc] initWithObjects:#"a", #"d", #"r", nil];
NSString *combinedString = [NSString stringWithFormat:#"%# %# %#", array[0], array[1], array[2]];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"msg"
message:combinedString
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alert show];
i want localize stringWithFormat by this:
NSString *string = [NSString stringWithFormat:#"Login %d in",2013];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(#string, nil)
message:#"Message"
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:#"sure", nil];
[alertView show];
also i write this in Localizable.string:
"Login %d in" = "LOGIN %d IN";
and it doesn't work.can you help me?Thank...
You have to localize the format string itself. Doing anything else doesn't make sense because the string can be practically anything when it's formatted (that's the purpose of format strings, after all). Just out of curiosity, haven't you seen things like
"%d seconds remaining" = "%d secondes restants";
"Hello, %#!" = "Bonjour, %# !";
in the Localizable.strings file of applications you used yet?
NSString *localizedFmt = NSLocalizedString(#"Login %d in", nil);
UIAlertView *av = [[UIAlertView alloc]
initWithTitle:[NSString stringWithFormat:localizedFmt, 2013],
// etc...
];
The Security Freak's Notice: although this is the most common and easiest approach to localize formatted strings, it's not entirely safe.
An attacker can change the localized format string in the aforementioned Localizable.strings file of your app to something bogus, for example, to a string that contains more conversion specifiers than stringWithFormat: has arguments (or even mismatching specifiers - treating integers as pointers, anyone?), and then a stack smashing-based attack can be carried out against your application - so beware of hackers.
I have an app and am trying to submit scores to game center. this is my code:
- (IBAction) submitScore{
NSString *show = [[NSString alloc] initWithFormat:#"Note: Scores may take some time to update"];
self.note.text = show;
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Submitted"
message:#"Your score has been submitted to the Gamecenter leaderboard"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles: nil];
[alert show];
array = [NSMutableArray arrayWithContentsOfFile:Path];
NSString *s = [[NSNumber numberWithInteger:[array count]] stringValue];
NSString *denom = [NSString stringWithFormat: #"%d", 15];;
double resultInNum;
double sdouble = [s doubleValue];
double denomdouble = [denom doubleValue];
resultInNum = sdouble/denomdouble * 100;
if(resultInNum > 0)
{
self.currentLeaderBoard = kLeaderboardID;
[self.gameCenterManager reportScore: resultInNum forCategory: self.currentLeaderBoard];
Submit.enabled = NO;
}
array = [NSMutableArray arrayWithContentsOfFile:Path];
[array writeToFile:Path atomically:YES];
NSLog(#"Count: %i", [array count]);
}
however when i try to do it it does not submit to the leader board. there are no errors that i am receiving in the debugger, and it used to work until i added more than one leader board. whats wrong here?
Score value must be an int64_t.
And I don't get why you are using NSStrings instead of directly assigning values?
Just make sure that you do the correct code for submitting the score. This is a way that I really like. Even though you will get warnings because they don't want you to use it in iOS 7, it still works. Just let me know if it doesn't work.
(IBAction)submitscoretogamecenter{
GKLocalPlayer *localplayer = [GKLocalPlayer localPlayer];
[localplayer authenticateWithCompletionHandler:^(NSError *error) {
}];
//This is the same category id you set in your itunes connect GameCenter LeaderBoard
GKScore *myScoreValue = [[[GKScore alloc] initWithCategory:#"insertCategory"] autorelease];
myScoreValue.value = scoreInt;
[myScoreValue reportScoreWithCompletionHandler:^(NSError *error){
//insert what happens after it's posted
}];
[self checkAchievements];
}