Show UiAlertView if UILabel is Equal to empty - uilabel

then in my app the user must enter data compulsorily.
Some of these data is controlled by NSInteger and some labels that take into account the click of a button displaying the number.
Now I need that when the user pushes the button "Save" if the label does not contain a number, a UIAlertView warns him of the missing field.
Below I have tried to do this .. With labels, you can use this system?
- (IBAction)FFSalvaDati_ConvalidaEsame:(id)sender {
if (!FFVotazioneLabel == 0 || FFCFULabel == 0) {
UIAlertView *FFAlertConvalidaEsameError = [[UIAlertView alloc] initWithTitle:#"ATTENZIONE" message:#"Per procedere con la convalidazione è necessario inserire il numero dei CFU ottenuti per questo esame e la sua Votazione. \n \n Senza questi dati non ci è possibile calcolare la tua media attuale!" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[FFAlertConvalidaEsameError show];
} else {
}

You need to check the text of the label. Please consider checking again the code as I didn't test it myself. Do this:
- (IBAction)FFSalvaDati_ConvalidaEsame:(id)sender {
if ([FFVotazioneLabel.text isEqualToString:#""] || [FFCFULabel.text isEqualToString:#""]) {
UIAlertView *FFAlertConvalidaEsameError = [[UIAlertView alloc] initWithTitle:#"ATTENZIONE" message:#"Per procedere con la convalidazione è necessario inserire il numero dei CFU ottenuti per questo esame e la sua Votazione. \n \n Senza questi dati non ci è possibile calcolare la tua media attuale!" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[FFAlertConvalidaEsameError show];
} else {
}

Related

Database is locked while updating data in background

I'm working on an application where I've to use sqlite and there are lots of data. I want to load data from "residents_status" column of a table named "tblResident". it is taking too much time to load data of that column (residents_status) more than 8 seconds and other data takes just a second. During the period of fetching the data from "residents_status" column, if I press a button its give me 'query error'
in else part but if I click button after 8 seconds than it is working fine.
Here is my code:
if(sqlite3_exec(database, insert_stmt, NULL, NULL, &error)==SQLITE_OK)
{
NSLog(#"succeddd.....");
IsValidate = true;
if([self checkNetConnection])
{
[self UpdateServerWith_LocalDB];
NSString *Key= [DefaultsValues getStringValueFromUserDefaults_ForKey: #"Key"];
if([[DefaultsValues getStringValueFromUserDefaults_ForKey: #"LastAuthenticationStatus"] isEqualToString:#"false"]){
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:nil message:#"Your Access is Restrcited,Please contact us" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
}
}
}
else{
NSLog(#"query error");
ErrorMsg = [NSString stringWithFormat:#"%s", error ];
IsValidate = false;
}

Objective-c function

I'm trying to create a function in order to save some code, however I have no idea how I should do it.
if (count > 100 && count < 120)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Time is up!"
message:[NSString stringWithFormat:#"You're really good at this! You scored %i points", count - 1]
delegate:self
cancelButtonTitle:#"Play Again"
otherButtonTitles:nil];
[alert show];
}
else if(count > 120)
{
UIAlertView *alert2 = [[UIAlertView alloc] initWithTitle:#"Time is up!"
message:[NSString stringWithFormat:#"TEACH ME MASTER, YOU'RE A GOD! You scored %i points", count - 1]
delegate:self
cancelButtonTitle:#"Play Again"
otherButtonTitles:nil];
[alert2 show];
}
else
{
UIAlertView *alert3 = [[UIAlertView alloc] initWithTitle:#"Time is up!"
message:[NSString stringWithFormat:#"Not very good, you scored %i points", count - 1]
delegate:self
cancelButtonTitle:#"Play Again"
otherButtonTitles:nil];
[alert3 show];
}
As you can see the code is very repetitive and I would like to create a function where I can change the value of the "alert" variable and the message string. So when I call the function I only enter the functions name and the value the alert variable should have, in this case; 1, 2 and 3 and the message text depending on what condition we are looking at.
So is there some way of doing this? There has to be, because repetitive code like this is never good looking! I would appreciate if someone could help me out, I've tried looking at some references but none of them made me get any closer to solving the problem.
Simply look at the duplicated functionality and examine the values that are different. In this case it's just the message:
NSString *message = nil;
if (count > 100 && count < 120)
{
message = [NSString stringWithFormat:#"You're really good at this! You scored %i points", count - 1];
}
else if(count >= 120)
{
message = [NSString stringWithFormat:#"TEACH ME MASTER, YOU'RE A GOD! You scored %i points", count - 1];
}
else
{
message = [NSString stringWithFormat:#"Not very good, you scored %i points", count - 1];
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Time is up!"
message:message
delegate:self
cancelButtonTitle:#"Play Again"
otherButtonTitles:nil];
[alert show];
(Edit: You missed the value 120 which would have slipped through the cracks).
I am create a new function that creates a new alert with given message :
-(void)showAlertWithMsg:(NSString *)msg tag:(NSInteger)tag
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Time is up!"
message:msg
delegate:self
cancelButtonTitle:#"Play Again"
otherButtonTitles:nil];
alert.tag = tag;
[alert show];
}
To call this function write the below code:
if (count > 100 && count < 120)
{
[self showAlertWithMsg:[NSString stringWithFormat:#"You're really good at this! You scored %i points", count - 1] tag:1];
}
else if(count > 120)
{
[self showAlertWithMsg:[NSString stringWithFormat:#"TEACH ME MASTER, YOU'RE A GOD! You scored %i points", count - 1] tag:2];
}
else
{
[self showAlertWithMsg:[NSString stringWithFormat:#"Not very good, you scored %i points", count - 1] tag:3];
}
One more thing I am also pass the tag.So if you want to perform different operation for different alert.
You can set "title" property exactly for existing UIAlertView instance:
UIAlertView * alertView = [[UIAlertView allow] init...];
alertView.title = #"Some message here.";

Receive one-time message when approaching iBeacon

I playing a little around with iBeaconss and now set up my code so I receive a pop when I enter a beacon (with code below). Problem I run into now however that it keeps popping up.
Does anybody now how I have to set up my code so I only receive it once when I enter a region?
Regards,
Marc
if ([[NSString stringWithFormat:#"%#", beacon.minor] isEqualToString:#"51447"])
//hiermee kun je een pop-op geven met of hij wel of niet naar tweede scherm wil.
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:#"Open second screen?" delegate:self cancelButtonTitle:#"No" otherButtonTitles:#"Yes", nil];
[alertView show];
}
just remember it using a BOOL or a dictionary (for multiple
if ([[NSString stringWithFormat:#"%#", beacon.minor] isEqualToString:#"51447"])
//hiermee kun je een pop-op geven met of hij wel of niet naar tweede scherm wil.
{
if(![_shownRanges[#"51447"] boolValue]) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:#"Open second screen?" delegate:self cancelButtonTitle:#"No" otherButtonTitles:#"Yes", nil];
[alertView show];
if(!_shownRanges) {
_shownRanges = [NSMutableDictionary dictionary];
}
_shownRanges[#"51447"] = #YES;
}
}
(_shownRanges is a NSMutableDictionary that you define in your interface)

CBPeripheralManagerState shows always state = off

So I have this peripheralManager. I want to check, if the State of it is on or not:
if (peripheralManager.state < CBPeripheralManagerStatePoweredOn) {
UIAlertView *errorAlert = [[UIAlertView alloc] initWithTitle:#"Bluetooth must be enabled" message:#"To search for pics, you have to enable bluetooth." delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[errorAlert show];
}
I'm testing it on my iPhone 5 and the Bluetooth is clearly on. But it shows always, that it is off.
UPDATE
How can I fix it?

Checking for multiple variable value in Xcode

I am creating an iPhone app which is taking many values from the user and assigning them to variables.
I want to display an alert message if more than two of the variables' values are equal to zero.
Basically, if the user has two empty fields, it should show an alert stating that there is insufficient data.
Any idea how to do this?
Your question is a bit vague but what about
Find errors
Display an alert
Somewhere alone the lines of this pseudo code:
int errorCount = 0;
if(var1 == 0) {
errorCount++;
}
if(var2 == 0) {
errorCount++;
}
// check all variables...
// Show alert if there are any errors
if(errorCount > 0) {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:#"Title"
message:[NSString stringWithFormat:#"You have %d errors", errorCount]
delegate:nil
cancelButtonTitle:#"GoFightWin"
otherButtonTitles: nil, nil];
[alert show];
[alert release];
}