Making an app that uses a PickerView to drop pins - ios

Me and a group of friends are creating an iPhone app for a project in our technology class. Our app is going to be used for navigation to different high school sporting event locations in our area. We are currently using a PickerView to control all the combinations of school and sport. The picker has two components, one for schools and one for sports. We already have the MapView set up as well.
We are wondering how we can place the pins for all the different school/sport combinations using the outputs from the Picker View. As you can see in the code below, we currently have a ton of if/then statements to receive the outputs from the PickerView, but eventually want to make that less bulky as well.
Here is the code for the picker outputs:
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
int x = [pickerView selectedRowInComponent:0]; NSLog(#"Row 1: %i", x);
int y = [pickerView selectedRowInComponent:1]; NSLog(#"Row 2: %i", y);
//Blue Ridge
if (x == 0 && y == 0)
{NSLog(#"Blue Ridge Basketball");}
else if (x == 0 && y == 1)
{NSLog(#"Blue Ridge Basketball");}
else if (x == 0 && y == 2)
{NSLog(#"Blue Ridge Cross Country");}
else if (x == 0 && y == 3)
{NSLog(#"Blue Ridge Football");}
else if (x == 0 && y == 4)
{NSLog(#"Blue Ridge Golf");}
else if (x == 0 && y == 5)
{NSLog(#"Blue Ridge Soccer");}
else if (x == 0 && y == 6)
{NSLog(#"Blue Ridge Softball");}
else if (x == 0 && y == 7)
{NSLog(#"Blue Ridge Track");}
else if (x == 0 && y == 8)
{NSLog(#"Blue Ridge Volleyball");}
else if (x == 0 && y == 9)
{NSLog(#"Blue Ridge Wrestling");}
//DeeMack
else if (x == 1 && y == 0)
{NSLog(#"DeeMack Baseball");}
else if (x == 1 && y == 1)
{NSLog(#"DeeMack Basketball");}
else if (x == 1 && y == 2)
{NSLog(#"DeeMack Cross Country");}
else if (x == 1 && y == 3)
{NSLog(#"DeeMack Football");}
else if (x == 1 && y == 4)
{NSLog(#"DeeMack Golf");}
else if (x == 1 && y == 5)
{NSLog(#"DeeMack Soccer");}
else if (x == 1 && y == 6)
{NSLog(#"DeeMack Softball");}
else if (x == 1 && y == 7)
{NSLog(#"DeeMack Track");}
else if (x == 1 && y == 8)
{NSLog(#"DeeMack Volleyball");}
else if (x == 1 && y == 9)
{NSLog(#"DeeMack Wrestling");}
}
...etc, This format continues for 11 more schools.
Any ideas as to how we can use these outputs to drop the pins on the map, or ideas to make this code shorter would be greatly appreciated. Also it is important to note that we are all very new to coding, so the simpler the better. Thanks!

To make the code shorter, all you need to do is maintain 2 arrays, one containing the high school names and the other containing the sports.
So create 2 NSArrays as properties of your controller
#property (strong, nonatomic) NSArray *highSchools;
#property (strong, nonatomic) NSArray *sports;
and then in the viewDidLoad method, do this :
self.highSchools = [NSArray arrayWithObjects:#"Blue Ridge", #"DeeMack," nil];
self.sports = [NSArray arrayWithObjects:#"Baseball", #"BasketBall", #"Cross Country", nil];
So now your picker delegate method will reduce to this ::
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
int x = [pickerView selectedRowInComponent:0]; NSLog(#"Row 1: %i", x);
int y = [pickerView selectedRowInComponent:1]; NSLog(#"Row 2: %i", y);
NSLog(#"%# %#", [self.highSchools objectAtIndex:x], [self.sports objectAtIndex:y]);
}
Now, for placing the pins, its not clear from the question, exactly how or where you want to place them and what the pins represent. It seems like you want to drop a single pin on the map depending on a school/sport combination at the location of the selected school. Is that right?

Related

Dafny cannot prove that 'a^2<=b^2*c^2' implies 'a<=b*c' for reals greater than 0

I want to test the following property in Dafny: a^2<=b^2*c^2 implies a<=b*c. It automatically checks this for (positive) integer numbers:
lemma powersVSsquares_integers(a:int, b:int, c:int)
requires a>=0 && b>=0 && c>= 0
ensures (a*a <= b*b*c*c) ==> (a<=b*c)
{}
Now, I want to test this for real numbers, so I try:
lemma powersVSsquares_reals(a:real, b:real, c:real)
requires a>=0.0 && b>=0.0 && c>=0.0
ensures (a*a <= b*b*c*c) ==> (a<=b*c)
{}
But Dafny cannot prove this. Thus, I start with the case where a>=1.0 & b>=1.0 & c>=1.0:
lemma powersVSsquares_reals1(a:real, b:real, c:real)
requires (a>=1.0 && b>=1.0 && c>=1.0)
ensures (a*a <= b*b*c*c) ==> (a<=b*c)
{
assert a <= (b*b*c*c)/a;
}
But not even assert a <= (b*b*c*c)/a; can be proven. So I have no idea on how to deal with this prove.
Can anyone provide lemma powersVSsquares_reals proven in Dafny? Can this be done without defining a symbolic square root function?
I think you will need some axioms of the reals that are not readily available in Dafny.
lemma increase(a: real, b: real, x: real)
requires x > 0.0
requires a > b
ensures a * x > b * x
{
}
lemma zero(a: real)
requires a*a == 0.0
ensures a == 0.0
{
if a != 0.0 {
if a > 0.0 {
increase(a, 0.0, a);
assert false;
} else if a < 0.0 {
increase(-a, 0.0, -a);
assert false;
}
}
}
Then you can use these axioms to do a regular proof. Here I choose the style of a proof by contradiction
lemma powersVSsquares_reals(a:real, b:real, c:real)
requires a>=0.0 && b>=0.0 && c>=0.0
ensures (a*a <= (b*b)*(c*c)) ==> (a<=b*c)
{
if a*a <= (b*b)*(c*c) {
if a == 0.0 {
return;
}
if b == 0.0 || c == 0.0 {
zero(a);
return;
}
assert a*a <= (b*c)*(b*c);
if a > (b*c) {
assert b * c > 0.0;
increase(a, b*c, b*c);
assert a * (b*c) > (b * c) * (b*c);
assert a > 0.0;
increase(a, b*c, a);
assert a * a > (b * c) * a;
assert a * a > (b * c) * (b*c);
assert false;
}
assert a<=b*c;
}
}

Objective C - Only part of an if condition working

I have an if statement and the statement is only being run on the fist third of the condition (before the fist 'or' (||).
if (((day == 1) && (period == 1)) || ((day == 3) && (period == 3)) || ((day = 5) && (period == 1)))
{
NSLog(#"Return Line 1");
}
The condition is only met when day = 1 and period = 1. Could someone help me get the other arrangements working in the condition. Thank you in advance.
if (((day == 1) && (period == 1)) || ((day == 3) && (period == 3)) || ((day == 5) && (period == 1)))
{
NSLog(#"Return Line 1");
}
In your code there is only one = instead of ==
The error in your code is ((day = 5) && (period == 1))

Simple IF statement with ActionScript 2.0

Hi and please do not judge my poor scripting or advice me to move to AS 3.0 or give me a solution that has absolutely ridiculous amount of scripting.
Just tell me what I'm doing wrong, I'll handle the rest. Thanks.
Basicly, I want to show certain pages depending on the x variable. But this code always ends up in gotoAndStop("2") even if the x variable is greater than -5, so the code doesn't work.
Here's my code:
if (x <= -5) {
gotoAndStop("2");
} else if ((x > -5) && (x < 0)) {
gotoAndStop("3");
} else if (x == 0) {
gotoAndStop("4");
} else if ((x > 0) && (x < 5)) {
gotoAndStop("5");
} else if (x >= 5) {
gotoAndStop("6");
}

A* only works in certain cases

My a* path finding algorithm only works for certain cases but I don't understand why. Every node in my grid is walkable so in theory every path should work. I believe the error is in this line:
PathFindingNode *neighbor = NULL;
if ((y > 0 && x > 0) && (y < gridY - 1 && x < gridX - 1))
neighbor = [[grid objectAtIndex:x + dx] objectAtIndex:y +dy];
In function -(void)addNeighbors:, the line
if ((y > 0 && x > 0) && (y < gridY - 1 && x < gridX - 1))
neighbor = [[grid objectAtIndex:x + dx] objectAtIndex:y +dy];
has bug because if curNode is on boundary, it does not add neighbors to the queue. So that the algorithm will never reach endNode in the four corners (i.e. [0,0], [gridX-1,0], [0,gridY-1], [gridX-1,gridY-1]).

Logical operators and wrong result in Objective C

I got the x and y by a UITapGestureRecognizer set on the screen, after having obtained the location I find the object touched, so I put the conditions, but does not work. Maybe I put the wrong conditions in objective C? Xcode gives no errors but the function does not work.
-(void)tappedMapOniPad:(int)x andy:(int)y{
NSLog(#"the x is: %d", x);
//the x is: 302
NSLog(#"the y is: %d", y);
//the y is: 37
if((121<x<=181) && (8<y<=51)){ //the error is here
self.stand = 431;
}else if ((181<x<=257) && (8<y<=51)){
self.stand=430;
}else if ((257<x<=330) && (8<y<=51)){
self.stand = 429;
}
NSLog(#"The stand is %d", self.stand);
//The stand is 431
}
How can I do?
121<x<=181
let's assume x := 10 121<10<=181 -> false<=181 -> 0<=181 -> true
you have to do it step by step.
((121 < x) && (x <=181))
let's assume x := 10 ((121 < 10) && (10 <=181)) ->false && true ->false
Replace
if((121<x<=181) && (8<y<=51))
by
if((121 < x && x <= 181) && (8 < y && y <= 51))
(121<x<=181) kind of expression is invalid in Obj-c.
Use, (x>121 && x<=181)
Your full code will be like :
if((x>121 && x<=181) && (y>8 && y<=51)){ //the error is here
self.stand = 431;
}
else if ((x>181 && x<=257) && (y>8 && y<=51)){
self.stand=430;
}
else if ((x> 255 && x<=330) && (y>8 && y<=51)){
self.stand = 429;
}
Or you can optimize it as:
if(y>8 && y<=51){
if (x> 257 && x<=330) {
self.stand = 429;
}
else if(x>181){
self.stand=430;
}
else if(x>121){
self.stand = 431;
}
}
Missing &&
Try
if((121<x&&x <=181)&&(8<y&&y <=51))
Hope it helps

Resources