WEBI BO Based on today display next day (dayname) if value match - date

Hi So I have table with booking dates which is just 2 columns...
country and bookings
each country can be booked only on one day. Monday - Friday and that "day" is indicated in second column.
Is there a calculation available to say based on today what the next slot is: (based on Day from table) but if today is Monday and slots are on Monday it will display date for next Monday etc....
so basically today (Wednesday) i need a calculation that will check what is the next booking available and show the date:
so if next one is Thursday in file I need it to display 14/03/2019
if in the file is Wednesday I would need it to display next week as today is to late so 20/03/2019

in case anybody is looking for the same thing...
I've got it working... maybe not the most beautiful solution but works..
= If [v Next Dry]="Monday" And DayName(CurrentDate()) ="Monday" Then RelativeDate(CurrentDate();7)
ElseIf [v Next Dry]="Monday" And DayName(CurrentDate()) ="Tuesday" Then RelativeDate(CurrentDate();6)
ElseIf [v Next Dry]="Monday" And DayName(CurrentDate()) ="Wednesday" Then RelativeDate(CurrentDate();5)
ElseIf [v Next Dry]="Monday" And DayName(CurrentDate()) ="Thursday" Then RelativeDate(CurrentDate();4)
ElseIf [v Next Dry]="Monday" And DayName(CurrentDate()) ="Friday" Then RelativeDate(CurrentDate();3)
ElseIf [v Next Dry]="Monday" And DayName(CurrentDate()) ="Saturday" Then RelativeDate(CurrentDate();2)
ElseIf [v Next Dry]="Monday" And DayName(CurrentDate()) ="Sunday" Then RelativeDate(CurrentDate();1)
ElseIf [v Next Dry]="Tuesday" And DayName(CurrentDate()) ="Monday" Then RelativeDate(CurrentDate();1)
ElseIf [v Next Dry]="Tuesday" And DayName(CurrentDate()) ="Tuesday" Then RelativeDate(CurrentDate();7)
ElseIf [v Next Dry]="Tuesday" And DayName(CurrentDate()) ="Wednesday" Then RelativeDate(CurrentDate();6)
ElseIf [v Next Dry]="Tuesday" And DayName(CurrentDate()) ="Thursday" Then RelativeDate(CurrentDate();5)
ElseIf [v Next Dry]="Tuesday" And DayName(CurrentDate()) ="Friday" Then RelativeDate(CurrentDate();4)
ElseIf [v Next Dry]="Tuesday" And DayName(CurrentDate()) ="Saturday" Then RelativeDate(CurrentDate();3)
ElseIf [v Next Dry]="Tuesday" And DayName(CurrentDate()) ="Sunday" Then RelativeDate(CurrentDate();2)
ElseIf [v Next Dry]="Wednesday" And DayName(CurrentDate()) ="Monday" Then RelativeDate(CurrentDate();2)
ElseIf [v Next Dry]="Wednesday" And DayName(CurrentDate()) ="Tuesday" Then RelativeDate(CurrentDate();1)
ElseIf [v Next Dry]="Wednesday" And DayName(CurrentDate()) ="Wednesday" Then RelativeDate(CurrentDate();7)
ElseIf [v Next Dry]="Wednesday" And DayName(CurrentDate()) ="Thursday" Then RelativeDate(CurrentDate();6)
ElseIf [v Next Dry]="Wednesday" And DayName(CurrentDate()) ="Friday" Then RelativeDate(CurrentDate();5)
ElseIf [v Next Dry]="Wednesday" And DayName(CurrentDate()) ="Saturday" Then RelativeDate(CurrentDate();4)
ElseIf [v Next Dry]="Wednesday" And DayName(CurrentDate()) ="Sunday" Then RelativeDate(CurrentDate();3)
ElseIf [v Next Dry]="Thursday" And DayName(CurrentDate()) ="Monday" Then RelativeDate(CurrentDate();3)
ElseIf [v Next Dry]="Thursday" And DayName(CurrentDate()) ="Tuesday" Then RelativeDate(CurrentDate();2)
ElseIf [v Next Dry]="Thursday" And DayName(CurrentDate()) ="Wednesday" Then RelativeDate(CurrentDate();1)
ElseIf [v Next Dry]="Thursday" And DayName(CurrentDate()) ="Thursday" Then RelativeDate(CurrentDate();7)
ElseIf [v Next Dry]="Thursday" And DayName(CurrentDate()) ="Friday" Then RelativeDate(CurrentDate();6)
ElseIf [v Next Dry]="Thursday" And DayName(CurrentDate()) ="Saturday" Then RelativeDate(CurrentDate();5)
ElseIf [v Next Dry]="Thursday" And DayName(CurrentDate()) ="Sunday" Then RelativeDate(CurrentDate();4)
ElseIf [v Next Dry]="Friday" And DayName(CurrentDate()) ="Monday" Then RelativeDate(CurrentDate();4)
ElseIf [v Next Dry]="Friday" And DayName(CurrentDate()) ="Tuesday" Then RelativeDate(CurrentDate();3)
ElseIf [v Next Dry]="Friday" And DayName(CurrentDate()) ="Wednesday" Then RelativeDate(CurrentDate();2)
ElseIf [v Next Dry]="Friday" And DayName(CurrentDate()) ="Thursday" Then RelativeDate(CurrentDate();1)
ElseIf [v Next Dry]="Friday" And DayName(CurrentDate()) ="Friday" Then RelativeDate(CurrentDate();7)
ElseIf [v Next Dry]="Friday" And DayName(CurrentDate()) ="Saturday" Then RelativeDate(CurrentDate();6)
ElseIf [v Next Dry]="Friday" And DayName(CurrentDate()) ="Sunday" Then RelativeDate(CurrentDate();5)
ElseIf [v Next Dry]="Saturday" And DayName(CurrentDate()) ="Monday" Then RelativeDate(CurrentDate();5)
ElseIf [v Next Dry]="Saturday" And DayName(CurrentDate()) ="Tuesday" Then RelativeDate(CurrentDate();4)
ElseIf [v Next Dry]="Saturday" And DayName(CurrentDate()) ="Wednesday" Then RelativeDate(CurrentDate();3)
ElseIf [v Next Dry]="Saturday" And DayName(CurrentDate()) ="Thursday" Then RelativeDate(CurrentDate();2)
ElseIf [v Next Dry]="Saturday" And DayName(CurrentDate()) ="Friday" Then RelativeDate(CurrentDate();1)
ElseIf [v Next Dry]="Saturday" And DayName(CurrentDate()) ="Saturday" Then RelativeDate(CurrentDate();7)
ElseIf [v Next Dry]="Saturday" And DayName(CurrentDate()) ="Sunday" Then RelativeDate(CurrentDate();6)
ElseIf [v Next Dry]="Sunday" And DayName(CurrentDate()) ="Monday" Then RelativeDate(CurrentDate();6)
ElseIf [v Next Dry]="Sunday" And DayName(CurrentDate()) ="Tuesday" Then RelativeDate(CurrentDate();5)
ElseIf [v Next Dry]="Sunday" And DayName(CurrentDate()) ="Wednesday" Then RelativeDate(CurrentDate();4)
ElseIf [v Next Dry]="Sunday" And DayName(CurrentDate()) ="Thursday" Then RelativeDate(CurrentDate();3)
ElseIf [v Next Dry]="Sunday" And DayName(CurrentDate()) ="Friday" Then RelativeDate(CurrentDate();2)
ElseIf [v Next Dry]="Sunday" And DayName(CurrentDate()) ="Saturday" Then RelativeDate(CurrentDate();1)
ElseIf [v Next Dry]="Sunday" And DayName(CurrentDate()) ="Sunday" Then RelativeDate(CurrentDate();7)

Related

Display more than one image in screen

I have imageView under scrollview. When i select particular image from scrollview it displays center of the screen. When i select another image, the previous image will goes off. I can't display more than one image in screen.
code:
- (void)viewDidAppear:(BOOL)animated {
myImageView = [[UIImageView alloc]initWithFrame:CGRectMake(100, 10, 200, 200)];
[self.view addSubview:myImageView];
}
- (void)loadNextPage:(int)index {
int countFlag = 0;
for(int i=index*4;i<(index+1)*4;i++)
{
UIButton *imageView=[[UIButton alloc]initWithFrame:CGRectMake((320*index)+countFlag*80+ 2, 5, 75, 75)];
imageView.tag=i+1;
[imageView addTarget:self action:#selector(imageViewClicked:) forControlEvents:UIControlEventTouchUpInside];
//[imageView.layer setBorderColor:[UIColor lightGrayColor].CGColor];
// [imageView.layer setBorderWidth:1.0f];
switch ((i+1)%15) {
case 0:
[imageView setImage:[UIImage imageNamed:#"img.png"] forState:UIControlStateNormal];
break;
case 1:
[imageView setImage:[UIImage imageNamed:#"img1.png"] forState:UIControlStateNormal];
break;
case 2:
[imageView setImage:[UIImage imageNamed:#"img2.png"] forState:UIControlStateNormal];
break;
case 3:
[imageView setImage:[UIImage imageNamed:#"img3.png"] forState:UIControlStateNormal];
break;
case 4:
[imageView setImage:[UIImage imageNamed:#"img4.png"] forState:UIControlStateNormal];
break;
case 5:
[imageView setImage:[UIImage imageNamed:#"img5.png"] forState:UIControlStateNormal];
break;
break;
}
[myScrollView addSubview:imageView];
countFlag++;
}
}
- (void)imageViewClicked:(id)sender{
switch ([sender tag]%15) {
case 0:
[myImageView setImage:[UIImage imageNamed:#"img.png"]];
// myImageView.tag=1;
[myImageView setTag:0];
break;
case 1:
[myImageView setImage:[UIImage imageNamed:#"img1.png"]];
// myImageView.tag=2;
[myImageView setTag:1];
break;
case 2:
[myImageView setImage:[UIImage imageNamed:#"img2.png"]];
[myImageView setTag:2];
break;
case 3:
[myImageView setImage:[UIImage imageNamed:#"img3.png"]];
[myImageView setTag:3];
break;
case 4:
[myImageView setImage:[UIImage imageNamed:#"img4.png"]];
[myImageView setTag:4];
break;
case 5:
[myImageView setImage:[UIImage imageNamed:#"img5.png"]];
[myImageView setTag:5];
break;
}
[self.view addSubview:myImageView];
}

UIButtons ,which are dynamic, not changeing its background image properly as per selected button's tag.

-(void)setButtons_AsPerTheMatrixSelection
{
int x = 7;
int y = 60;
for (int j = 0; j <= 35; ++j)
{
if (j <= 5)
btnMatrix = [[UIButton alloc] initWithFrame:CGRectMake(x, y, width, height)];
else if (j > 5 && j <= 11)
btnMatrix = [[UIButton alloc] initWithFrame:CGRectMake(x-306, y+51, width, height)];
else if (j > 11 && j <= 17)
btnMatrix = [[UIButton alloc] initWithFrame:CGRectMake(x-612, y+102, width, height)];
else if (j > 17 && j <= 23)
btnMatrix = [[UIButton alloc] initWithFrame:CGRectMake(x-918, y+153, width, height)];
else if (j > 23 && j <= 29)
btnMatrix = [[UIButton alloc] initWithFrame:CGRectMake(x-1224, y+204, width, height)];
else if (j > 29 && j <= 35)
btnMatrix = [[UIButton alloc] initWithFrame:CGRectMake(x-1530, y+255, width, height)];
btnMatrix.tag = j;
[btnMatrix setBackgroundImage:imgDefaultBG forState:UIControlStateNormal];
btnMatrix.userInteractionEnabled = TRUE;
[btnMatrix addTarget:self action:#selector(changeImage:) forControlEvents:UIControlEventTouchUpInside];
[viewWithButtons addSubview:btnMatrix];
[self.view addSubview:viewWithButtons];
x = x + 51;
y = y;
[arrButton addObject:btnMatrix];
}
}
This is my code to add dynamic buttons as per the matrix of 6*6
here i am adding the button tag also,
Now i am going to click on button & would like to change background image with this code...
-(void)changeImage:(id)sender
{
UIImage *img = [UIImage imageNamed:#"No.png"];
UIButton *tmpButton = (UIButton *)[self.view viewWithTag:btnMatrix.tag];
NSLog(#"btn.tag is... %d",tmpButton.tag);
[btnMatrix setBackgroundImage:img forState:UIControlStateNormal];
}
When i click to any button it always changing image of last tagged button...
i have to change Background of the selected button itself.
how can it be possible.
Please guide me i am not getting a part where i am doing a mistake.
Thanks.
-(void)changeImage:(UIButton*)sender
{
UIImage *img = [UIImage imageNamed:#"No.png"];
[sender setBackgroundImage:img forState:UIControlStateNormal];
}
BTW, your code is too messy, you may do like this
int pw = 306;
int ph = 51;
int ch = 6;
int cv = 6;
for ( int i = 0 ; i < cv ; ++i )
{
for ( int j = 0 ; j < ch ; ++j )
{
UIButton *btnMatrix = [[[UIButton alloc] initWithFrame:CGRectMake(7+pw*j, 51+ph*i, width, height)] autorelease];
btnMatrix.tag = i*ch+j;
}
}
Try this change in this method:
-(void)changeImage:(id)sender
{
UIButton *Btnmatrix = (UIButton *)sender
UIImage *img = [UIImage imageNamed:#"No.png"];
[Btnmatrix setBackgroundImage:img forState:UIControlStateNormal];
}
in your function
-(void)setButtons_AsPerTheMatrixSelection
make your button local as follow
for (int j = 0; j <= 35; ++j)
{
if (j <= 5){
UIButton *btnMatrix = [[UIButton alloc] initWithFrame:CGRectMake(x, y, width, height)];
btnMatrix.tag = j;
[btnMatrix setBackgroundImage:imgDefaultBG forState:UIControlStateNormal];
btnMatrix.userInteractionEnabled = TRUE;
[btnMatrix addTarget:self action:#selector(changeImage:) forControlEvents:UIControlEventTouchUpInside];
[viewWithButtons addSubview:btnMatrix];
}
// and so on every button
}
Hope this will help you. sorry for my bad english :)
It seems to me like btnMatrix is an ivar, and since you assign it successively to each button as you add them, it will hold a reference to your last button after you are done creating buttons. Change your line to inspect the sender object instead:
UIButton *tmpButton = (UIButton*)sender.tag;

Issue in if/else block objective-c iPhone [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I am using the below code for assigning values to my labels and imageviews but its not working properly. I am not getting the issue
if ([child11 length] != 0) {
[childButton1 setAlpha:1];
[childButton2 setAlpha:0];
[childButton3 setAlpha:0];
[childButton4 setAlpha:0];
[childButton5 setAlpha:0];
[childButton6 setAlpha:0];
//label1.text = child11;
NSLog(#"here we are");
if ([child11image isEqualToString:#"Fajar"]) {
image1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Blue-Jaanamaz-Small"]];
NSLog(#"child11image::: %#", child11image);
label1.text = child11;
} else if ([child11image isEqualToString:#"Zuhr"]) {
image1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Orange-Jaanamaz-Small"]];
label1.text = child11;
} else if ([child11image isEqualToString:#"Asr"]) {
image1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Pink-Jaanamaz-Large"]];
label1.text = child11;
NSLog(#"child11image::: %#", child11image);
} else if ([child11image isEqualToString:#"Maghrib"]) {
image1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Green-Jaanamaz-Small"]];
label1.text = child11;
} else if ([child11image isEqualToString:#"Isha"]) {
image1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Purple-Jaanamaz-Small"]];
label1.text = child11;
}
} else if ([child22 length] != 0){
[childButton1 setAlpha:1];
[childButton2 setAlpha:1];
[childButton3 setAlpha:0];
[childButton4 setAlpha:0];
[childButton5 setAlpha:0];
[childButton6 setAlpha:0];
label2.text = child22;
if ([child22image isEqualToString:#"Fajar"]) {
image2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Blue-Jaanamaz-Small"]];
} else if ([child22image isEqualToString:#"Zuhr"]) {
image2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Orange-Jaanamaz-Small"]];
} else if ([child22image isEqualToString:#"Asr"]) {
image2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Pink-Jaanamaz-Small"]];
} else if ([child22image isEqualToString:#"Maghrib"]) {
image2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Green-Jaanamaz-Small"]];
} else if ([child22image isEqualToString:#"Isha"]) {
image2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Purple-Jaanamaz-Small"]];
}
} else if ([child33 length] != 0){
[childButton1 setAlpha:1];
[childButton2 setAlpha:1];
[childButton3 setAlpha:1];
[childButton4 setAlpha:0];
[childButton5 setAlpha:0];
[childButton6 setAlpha:0];
label3.text = child33;
if ([child33image isEqualToString:#"Fajar"]) {
image3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Blue-Jaanamaz-Small"]];
} else if ([child33image isEqualToString:#"Zuhr"]) {
image3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Orange-Jaanamaz-Small"]];
} else if ([child33image isEqualToString:#"Asr"]) {
image3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Pink-Jaanamaz-Small"]];
} else if ([child33image isEqualToString:#"Maghrib"]) {
image3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Green-Jaanamaz-Small"]];
} else if ([child33image isEqualToString:#"Isha"]) {
image3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Purple-Jaanamaz-Small"]];
}
} else if ([child44 length] != 0) {
[childButton1 setAlpha:1];
[childButton2 setAlpha:1];
[childButton3 setAlpha:1];
[childButton4 setAlpha:1];
[childButton5 setAlpha:0];
[childButton6 setAlpha:0];
label4.text = child44;
if ([child44image isEqualToString:#"Fajar"]) {
image4 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Blue-Jaanamaz-Small"]];
} else if ([child44image isEqualToString:#"Zuhr"]) {
image4 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Orange-Jaanamaz-Small"]];
} else if ([child44image isEqualToString:#"Asr"]) {
image4 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Pink-Jaanamaz-Small"]];
} else if ([child44image isEqualToString:#"Maghrib"]) {
image4 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Green-Jaanamaz-Small"]];
} else if ([child44image isEqualToString:#"Isha"]) {
image4 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Purple-Jaanamaz-Small"]];
}
} else if ([child55 length] != 0) {
[childButton1 setAlpha:1];
[childButton2 setAlpha:1];
[childButton3 setAlpha:1];
[childButton4 setAlpha:1];
[childButton5 setAlpha:1];
[childButton6 setAlpha:0];
label5.text = child55;
if ([child55image isEqualToString:#"Fajar"]) {
image5 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Blue-Jaanamaz-Small"]];
} else if ([child55image isEqualToString:#"Zuhr"]) {
image5 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Orange-Jaanamaz-Small"]];
} else if ([child55image isEqualToString:#"Asr"]) {
image5 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Pink-Jaanamaz-Small"]];
} else if ([child55image isEqualToString:#"Maghrib"]) {
image5 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Green-Jaanamaz-Small"]];
} else if ([child55image isEqualToString:#"Isha"]) {
image5 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Purple-Jaanamaz-Small"]];
}
} else if ([child66 length] != 0) {
[childButton1 setAlpha:1];
[childButton2 setAlpha:1];
[childButton3 setAlpha:1];
[childButton4 setAlpha:1];
[childButton5 setAlpha:1];
[childButton6 setAlpha:1];
label6.text = child66;
if ([child66image isEqualToString:#"Fajar"]) {
image6 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Blue-Jaanamaz-Small"]];
} else if ([child66image isEqualToString:#"Zuhr"]) {
image6 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Orange-Jaanamaz-Small"]];
} else if ([child66image isEqualToString:#"Asr"]) {
image6 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Pink-Jaanamaz-Small"]];
} else if ([child66image isEqualToString:#"Maghrib"]) {
image6 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Green-Jaanamaz-Small"]];
} else if ([child66image isEqualToString:#"Isha"]) {
image6 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Purple-Jaanamaz-Small"]];
}
} else ([child11 length] == 0) {
[childButton1 setAlpha:0];
[childButton2 setAlpha:0];
[childButton3 setAlpha:0];
[childButton4 setAlpha:0];
[childButton5 setAlpha:0];
[childButton6 setAlpha:0];
}
You don't say what the actual problem is but the if statement has to be wrong. The first two conditions are
if ([child11 length] == 0)
{
// do stuff
}
else if ([child11 length] != 0)
{
// do stuff
}
else // nothing else matters
You will always go through one of the first two cases because (x == 0 || x != 0) == true by definition. All of the stuff to do with child22, child33 etc never gets done.
i think this is what you mean
if ([child11 length] != 0){
[childButton1 setAlpha:1]; [childButton2 setAlpha:0]; [childButton3 setAlpha:0]; [childButton4 setAlpha:0];
[childButton5 setAlpha:0]; [childButton6 setAlpha:0];
label1.text = child11;
if ([child11image isEqualToString:#"Fajar"]) {
image1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Blue-Jaanamaz-Small"]];
} else if ([child11image isEqualToString:#"Zuhr"]) {
image1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Orange-Jaanamaz-Small"]];
} else if ([child11image isEqualToString:#"Asr"]) {
image1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Pink-Jaanamaz-Large"]];
} else if ([child11image isEqualToString:#"Maghrib"]) {
image1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Green-Jaanamaz-Small"]];
} else if ([child11image isEqualToString:#"Isha"]) {
image1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Purple-Jaanamaz-Small"]];
}
} else if ([child22 length] != 0){
[childButton1 setAlpha:1]; [childButton2 setAlpha:1]; [childButton3 setAlpha:0]; [childButton4 setAlpha:0];
[childButton5 setAlpha:0]; [childButton6 setAlpha:0];
label2.text = child22;
if ([child22image isEqualToString:#"Fajar"]) {
image2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Blue-Jaanamaz-Small"]];
} else if ([child22image isEqualToString:#"Zuhr"]) {
image2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Orange-Jaanamaz-Small"]];
} else if ([child22image isEqualToString:#"Asr"]) {
image2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Pink-Jaanamaz-Small"]];
} else if ([child22image isEqualToString:#"Maghrib"]) {
image2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Green-Jaanamaz-Small"]];
} else if ([child22image isEqualToString:#"Isha"]) {
image2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Purple-Jaanamaz-Small"]];
}
} else if ([child33 length] != 0){
[childButton1 setAlpha:1]; [childButton2 setAlpha:1]; [childButton3 setAlpha:1]; [childButton4 setAlpha:0];
[childButton5 setAlpha:0]; [childButton6 setAlpha:0];
label3.text = child33;
if ([child33image isEqualToString:#"Fajar"]) {
image3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Blue-Jaanamaz-Small"]];
} else if ([child33image isEqualToString:#"Zuhr"]) {
image3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Orange-Jaanamaz-Small"]];
} else if ([child33image isEqualToString:#"Asr"]) {
image3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Pink-Jaanamaz-Small"]];
} else if ([child33image isEqualToString:#"Maghrib"]) {
image3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Green-Jaanamaz-Small"]];
} else if ([child33image isEqualToString:#"Isha"]) {
image3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Purple-Jaanamaz-Small"]];
}
} else if ([child44 length] != 0){
[childButton1 setAlpha:1]; [childButton2 setAlpha:1]; [childButton3 setAlpha:1]; [childButton4 setAlpha:1];
[childButton5 setAlpha:0]; [childButton6 setAlpha:0];
label4.text = child44;
if ([child44image isEqualToString:#"Fajar"]) {
image4 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Blue-Jaanamaz-Small"]];
} else if ([child44image isEqualToString:#"Zuhr"]) {
image4 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Orange-Jaanamaz-Small"]];
} else if ([child44image isEqualToString:#"Asr"]) {
image4 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Pink-Jaanamaz-Small"]];
} else if ([child44image isEqualToString:#"Maghrib"]) {
image4 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Green-Jaanamaz-Small"]];
} else if ([child44image isEqualToString:#"Isha"]) {
image4 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Purple-Jaanamaz-Small"]];
}
} else if ([child55 length] != 0){
[childButton1 setAlpha:1]; [childButton2 setAlpha:1]; [childButton3 setAlpha:1]; [childButton4 setAlpha:1];
[childButton5 setAlpha:1]; [childButton6 setAlpha:0];
label5.text = child55;
if ([child55image isEqualToString:#"Fajar"]) {
image5 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Blue-Jaanamaz-Small"]];
} else if ([child55image isEqualToString:#"Zuhr"]) {
image5 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Orange-Jaanamaz-Small"]];
} else if ([child55image isEqualToString:#"Asr"]) {
image5 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Pink-Jaanamaz-Small"]];
} else if ([child55image isEqualToString:#"Maghrib"]) {
image5 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Green-Jaanamaz-Small"]];
} else if ([child55image isEqualToString:#"Isha"]) {
image5 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Purple-Jaanamaz-Small"]];
}
} else if ([child66 length] != 0){
[childButton1 setAlpha:1]; [childButton2 setAlpha:1]; [childButton3 setAlpha:1]; [childButton4 setAlpha:1];
[childButton5 setAlpha:1]; [childButton6 setAlpha:1];
label6.text = child66;
if ([child66image isEqualToString:#"Fajar"]) {
image6 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Blue-Jaanamaz-Small"]];
} else if ([child66image isEqualToString:#"Zuhr"]) {
image6 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Orange-Jaanamaz-Small"]];
} else if ([child66image isEqualToString:#"Asr"]) {
image6 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Pink-Jaanamaz-Small"]];
} else if ([child66image isEqualToString:#"Maghrib"]) {
image6 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Green-Jaanamaz-Small"]];
} else if ([child66image isEqualToString:#"Isha"]) {
image6 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Purple-Jaanamaz-Small"]];
}
} else {
[childButton1 setAlpha:0]; [childButton2 setAlpha:0]; [childButton3 setAlpha:0]; [childButton4 setAlpha:0];
[childButton5 setAlpha:0]; [childButton6 setAlpha:0];
}
The issue i found this code is if a condition occur like if ([child11 length] == 0) and if ([child11 length] !=0) the childButton1, childButton2 setAlpha: will be 1. I think you have to do the childButton1 setAlpha as 0 and childButton2 setAlpha as 1 if the above condition occures. I dont know what you exactly need
And one thing. Don't write codes just like this. Use switch cases and enumes to improve the code readability and performance. happy coding.
If [child11 length] != 0 you will never reach the other else-if checks. (I am guessing child11 and child22 can be non empty.
And you must improve your code! Start by learning examples of basic iphone apps spread all over the network.

Change to rows in two differents components in a UIPickerView

I have the following code that should change the selected rows in two different components in a UIPickerView, but only the first one changes.
[pickerView selectRow:[pickerView selectedRowInComponent:0] inComponent:1 animated:TRUE];
[pickerView selectRow:[pickerView selectedRowInComponent:1] inComponent:0 animated:TRUE];
But when i do the following, they both change.
[pickerView selectRow:5 inComponent:0 animated:TRUE];
[pickerView selectRow:3 inComponent:1 animated:TRUE];
What is wrong with the first code, why is it not working?
Probably because they refer to each others.
You should record the selected row and then use it:
NSInteger selectedRowInFirst = [pickerView selectedRowInComponent:0];
NSInteger selectedRowInSecond = [pickerView selectedRowInComponent:1];
[pickerView selectRow:selectedRowInFirst inComponent:1 animated:TRUE];
[pickerView selectRow:selectedRowInSecond inComponent:0 animated:TRUE];
You are overriding the value of the selected row in component 1 in the first statement with the value from component 0. Then in the second statement you are using that same value you just copied to set row selection in component 0 again.
Thus you are setting component 0 back to its own original selected value.
You need to do something like this:
int comp1OriginalRowValue = [pickerView selectedRowInComponent:1];
[pickerView selectRow:[pickerView selectedRowInComponent:0] inComponent:1 animated:TRUE];
[pickerView selectRow:comp1OriginalRowValue inComponent:0 animated:TRUE];

CGPointMake question for iphone?

I have birds flying within a frame in my game, but I can only get them to fly in two different directions. If there are 2 birds they go in two different directions. If there are 3 birds, 2 of them go in one direction and the other one goes in a different direction. I want the birds to randomly go in four different directions. Up right, down right, up left and down left, here is my code.
-(void) AddBirdIntoArray: (int) BirdCount {
for(int i=0; i< BirdCount ; i++){
if(appDelegate.enemyselect == 0){
imgBird[i]=[[UIImageView alloc] initWithImage:firstImage];
[imgBird[i] setAnimationImages:birdArrayConstant];
}
else if(appDelegate.enemyselect == 1){
imgBird[i]=[[UIImageView alloc] initWithImage:firstImagegreenorange];
[imgBird[i] setAnimationImages:birdArrayConstant3];
}
else if(appDelegate.enemyselect == 2){
imgBird[i]=[[UIImageView alloc] initWithImage:firstImageblueyellow];
[imgBird[i] setAnimationImages:birdArrayConstant4];
}
else if(appDelegate.enemyselect == 3){
imgBird[i]=[[UIImageView alloc] initWithImage:firstImagebluewhite];
[imgBird[i] setAnimationImages:birdArrayConstant2];
}
else if(appDelegate.enemyselect == 4){
imgBird[i]=[[UIImageView alloc] initWithImage:firstImagepinkpurple];
[imgBird[i] setAnimationImages:birdArrayConstant5];
}
else if(appDelegate.enemyselect == 5){
imgBird[i]=[[UIImageView alloc] initWithImage:firstImagebluegreen];
[imgBird[i] setAnimationImages:birdArrayConstant6];
}
else if(appDelegate.enemyselect == 6){
imgBird[i]=[[UIImageView alloc] initWithImage:firstImageorangewhite];
[imgBird[i] setAnimationImages:birdArrayConstant7];
}
else if(appDelegate.enemyselect == 7){
imgBird[i]=[[UIImageView alloc] initWithImage:firstImageredblue];
[imgBird[i] setAnimationImages:birdArrayConstant8];
}
[imgBird[i] setAnimationDuration:1.0];
[imgBird[i] startAnimating];
if(i%2==0){
pos[i]=CGPointMake(-1,1);
}
else{
pos[i]=CGPointMake(1,-1);
}
xvalue = arc4random()%250;
yvalue = arc4random()%250;
CGRect TempRect = CGRectMake(xvalue ,yvalue , 22 , 22);
imgBird[i].frame = TempRect;
[birdImageViewArray addObject:imgBird[i]];
[self addSubview:imgBird[i]];
[imgBird[i] release];
}
[birdArray release];
}
I think these are your two direction vectors:
pos[i]=CGPointMake(-1,1);
pos[i]=CGPointMake(1,-1);
The other two directions are:
pos[i]=CGPointMake(-1,-1);
pos[i]=CGPointMake(1,1);
And, of course, rather than the if/else based on i%2, you should use a switch based on:
arc4random()%4