i have lots of if else condition how to reduce them - objective-c

I have a text field and used numberOfRowsInSection for creating more than 50 text fields. After that I use the if else condition, but it was time consuming and a lengthy method so I want to reduce my if else condition. I don't want to use the switch condition. What should I do?
if (textField.tag == 0)//cust add line 1
{
[_customerFormTableView setContentOffset : CGPointMake(0, 0)];
}
else if (textField.tag == 1)//cust add line 2
{
[_customerFormTableView setContentOffset : CGPointMake(0, 0)];
}
else if (textField.tag == 2)//kyc line 1
{
[_customerFormTableView setContentOffset : CGPointMake(0, 50)];
}
else if (textField.tag == 3)// kyc line 2
{
[self.view endEditing : YES];
DatePickerViewController *dateViewContrl = [self.storyboard instantiateViewControllerWithIdentifier : #"DatePickerViewController"];
dateViewContrl.delegate = self;
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
{
//dateViewContrl.preferredContentSize=CGSizeMake(325, 200);
dateViewContrl.preferredContentSize = CGSizeMake(290, 200);
}
popcontrol = [[WYPopoverController alloc] initWithContentViewController:dateViewContrl];
[popcontrol.delegate self];
// _currentfield=_dateTextField;
NSLog(#"%f %f",popcontrol.popoverContentSize.height,popcontrol.popoverContentSize.height);
CGRect rect_ = [self.view convertRect : textField.frame fromView : textField.superview];
[popcontrol presentPopoverFromRect : rect_
inView : self.view
permittedArrowDirections : WYPopoverArrowDirectionAny
animated : YES
options : WYPopoverAnimationOptionScale];
return NO;
}
else if (textField.tag == 4)
{
[textField resignFirstResponder];
[self DropDownGendview : textField];
return NO;
}
else if (textField.tag == 5)
{
[_customerFormTableView setContentOffset : CGPointMake(0, 250)];
}
else if (textField.tag == 6)
{
[_customerFormTableView setContentOffset : CGPointMake(0, 310)];
}
else if (textField.tag == 7)
{
[_customerFormTableView setContentOffset : CGPointMake(0, 370)];
}
else if (textField.tag == 8 || textField.tag == 13 || textField.tag == 20)
{
[self.view endEditing : YES];
[self DropDownview : textField];
return NO;
}
else if (textField.tag == 9)
{
[_customerFormTableView setContentOffset : CGPointMake(0, 510)];
}
else if (textField.tag == 10)//cor email
{
[_customerFormTableView setContentOffset : CGPointMake(0, 630)];
}
else if (textField.tag == 11)//desig
{
[_customerFormTableView setContentOffset : CGPointMake(0, 700)];
}
else if (textField.tag == 12)//level
{
[_customerFormTableView setContentOffset : CGPointMake(0, 770)];
}
else if (textField.tag == 14)//level
{
[_customerFormTableView setContentOffset : CGPointMake(0, 910)];
}
else if (textField.tag == 15)//level
{
[_customerFormTableView setContentOffset : CGPointMake(0, 980)];
}
else if (textField.tag == 16)
{
[_customerFormTableView setContentOffset : CGPointMake(0, 1050)];
}
else if (textField.tag == 17)
{
[_customerFormTableView setContentOffset : CGPointMake(0, 1140)];
}
else if (textField.tag == 18)
{
[_customerFormTableView setContentOffset : CGPointMake(0, 1240)];
}
else if (textField.tag == 19)
{
[_customerFormTableView setContentOffset : CGPointMake(0, 1310)];
}
else if (textField.tag == 21)
{
NSLog(#"state dropdown %ld",(long)textField.tag);
}
else if (textField.tag == 22)
{
[_customerFormTableView setContentOffset : CGPointMake(0, 1520)];
}
else if (textField.tag == 23)
{
[_customerFormTableView setContentOffset : CGPointMake(0, 1590)];
}
else if (textField.tag == 24)
{
[_customerFormTableView setContentOffset : CGPointMake(0, 1660)];
}
else if (textField.tag == 25)
{
[_customerFormTableView setContentOffset : CGPointMake(0, 1730)];
}
else if (textField.tag == 26)
{
[self.view endEditing : YES];
[self dropDownPurposeView : textField];
return NO;
}

You can represent a lot of these if statements with data, using a struct:
typedef struct
{
int tag;
int pointX;
int pointY;
} Values;
const Values values[] = {
{0, 0, 0},
{1, 0, 0},
{2, 0, 50},
// etc
};
then iterate through values and determine if your tag is in it:
int i;
bool found = false;
for (i = 0; i < sizeof(values) / sizeof(values[0]); i++)
{
if (values[i].tag == textField.tag)
{
[_customerFormTableView setContentOffset: CGPointMake(values[i].pointX,
values[i].pointY)];
found = true;
break;
}
}
if (! found)
{
// do more complicated operations here
}
you can speed up the for statement with a binary search, if the tags are sorted.

You can try with switch case statement.It is better one instead of having lots of if else condition.If you use swit case it will improve your performance rather than having multiple if else condition.
A switch statement allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each switch
switch(expression){
case constant-expression :
statement(s);
break; /* optional */
case constant-expression :
statement(s);
break; /* optional */
/* you can have any number of case statements */
default : /* Optional */
statement(s);
}
Generally the expression used in a switch statement must have an integral or enumerated type or be of a class type in which the class has a single conversion function to an integral or enumerated type.
For more details go with this https://www.tutorialspoint.com/objective_c/switch_statement_in_objective_c.htm

Related

Tag in TextField not working

#import <UIKit/UIKit.h>
#interface CustomTF : UITextField
-(void)awakeFromNib;
#end
and
#import "CustomTF.h"
#implementation CustomTF
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
-(void)awakeFromNib
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{ // for iphone ....
self.textColor = [UIColor colorWithRed:51/255.0f green:51/255.0f blue:51/255.0f alpha:1];
// self.font = [UIFont fontWithName:#"HelveticaNeueLT-LightCond" size:15];
self.borderStyle = UITextBorderStyleRoundedRect;
self.font = [UIFont systemFontOfSize:15];
// self.placeholder = #"enter text";
self.autocorrectionType = UITextAutocorrectionTypeNo;
self.keyboardType = UIKeyboardTypeDefault;
self.returnKeyType = UIReturnKeyDefault;
self.clearButtonMode = UITextFieldViewModeWhileEditing;
self.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
self.font = [UIFont fontWithName:#"Helvetica" size:15];
}
else
{ // for ipad .....
self.textColor = [UIColor colorWithRed:51/255.0f green:51/255.0f blue:51/255.0f alpha:1];
// self.font = [UIFont fontWithName:#"Anivers-Regular" size:17];
self.font = [UIFont fontWithName:#"Helvetica" size:17];
}
// self.layer.borderColor = [UIColor blackColor].CGColor;
// self.layer.borderWidth = 1.0f;
}
#end
// creating setTimeTF at run time according to
numberOfTime=5;
for (int i=1; i<= numberOfTime; i++) {
setTimeLabel = [[CustomLBL alloc] initWithFrame:CGRectMake(lblX, lblY, lblW, lblH)];
setTimeTF = [[CustomTF alloc] initWithFrame:CGRectMake(tfX, tfY, tfW, tfH)];
setTimeTF.placeholder = #"HH:MM";
lblY = lblY + lblH + 10;
tfY = tfY + tfH + 10;
setTimeTF.borderStyle = UITextBorderStyleRoundedRect;
setTimeTF.font = [UIFont systemFontOfSize:15];
setTimeTF.autocorrectionType = UITextAutocorrectionTypeNo;
setTimeTF.keyboardType = UIKeyboardTypeDefault;
setTimeTF.returnKeyType = UIReturnKeyDone;
setTimeTF.clearButtonMode = UITextFieldViewModeWhileEditing;
setTimeTF.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
setTimeTF.delegate = self;
setTimeTF.backgroundColor=[UIColor clearColor];
if (i == 1) {
setTimeTF.tag = 11;
setTimeLabel.text = #"Set 1st Time";
}
else if (i == 2){
//setTimeTF.tag = 22;
setTimeLabel.text = #"Set 2nd Time";
}
else if (i == 3){
setTimeTF.tag = 33;
setTimeLabel.text = #"Set 3rd Time";
}
else if (i == 4){
setTimeTF.tag = 44;
setTimeLabel.text = #"Set 4th Time";
}
else if (i == 5){
setTimeTF.tag = 55;
setTimeLabel.text = #"Set 5th Time";
}
[setTimeVw addSubview:setTimeLabel];
[setTimeVw addSubview:setTimeTF];
}
MY Problem:
in delegate method of textFieldShouldBeginEditing , its not going to condition
if (textField == self.setTimeTF) and getting tag set always 55 (last tag)
#pragma mark - TextField Delegates
- (BOOL) textFieldShouldBeginEditing: (UITextField *) textField
{
if (textField == self.setTimeTF)
{
if (setTimeTF.tag == 11)
{
[self showTimePicker:setTimeTF.tag];
return NO;
}
else if (setTimeTF.tag == 22)
{
[self showTimePicker];
return NO;
}
else if (setTimeTF.tag == 33)
{
[self showTimePicker];
return NO;
}
else if (setTimeTF.tag == 44)
{
[self showTimePicker];
return NO;
}
else if (setTimeTF.tag == 55)
{
[self showTimePicker];
return NO;
}
}
return YES;
// return NO;
}

Objective-C - If statements

Quick qeustion, my code:
if (slider2.value == 1)
{
barHeight = 100;
}
else if (slider2.value == 2)
{
barHeight = 200;
}
else if (slider2.value == 3)
{
barHeight = 300;
}
else if (slider2.value == 4)
{
barHeight = 400;
}
else if (slider2.value == 5)
{
barHeight = 500;
}
else
{
barHeight = 600;
}
When I drag the slider from 1 to 6 I see the height of the bar change. But when I move from 6 to 1 the barHeight is stuck at 600 and does not return to 100. What am I missing?
Edit ( full statement ):
- (void)valueAgeChanged:(UISlider*)slider2
{
// DRAW BARS (skeme)
CGRect frame = CGRectMake(595, barX, 80, barHeight);
orangeView= [[UIView alloc] initWithFrame:frame];
orangeView.backgroundColor = [UIColor orangeColor];
[self.view addSubview:orangeView];
// Let slider 1 animate on set value
[slider2 setValue:((int)((slider2.value + 1) / 1.0) - 1.0) animated:NO];
if (slider2.value == 1) {
barHeight = 100;
}else if (slider2.value == 2) {
barHeight = 200;
// barX = 300;
}else if (slider2.value == 3) {
barHeight = 300;
}else if (slider2.value == 4) {
barHeight = 400;
}else if (slider2.value == 5) {
barHeight = 500;
}else if (slider2.value == 6) {
barHeight = 600;
}
}
You're adding a new orangeView every time your value is changed. So they are simply overlaying each other. The tallest view will remain on screen and when you add shorter views of the same colour you won't see them.
To fix this you could set up the orangeView property outside of your valueChanged method (maybe viewDidLoad) and add it as a subview.
Then whenever your slider updates only update the frame of your view.
e.g.
- (void)valueAgeChanged:(UISlider*)slider2
{
[slider2 setValue:((int)((slider2.value + 1) / 1.0) - 1.0) animated:NO];
if (slider2.value == 1) {
barHeight = 100;
}else if (slider2.value == 2) {
barHeight = 200;
// barX = 300;
}else if (slider2.value == 3) {
barHeight = 300;
}else if (slider2.value == 4) {
barHeight = 400;
}else if (slider2.value == 5) {
barHeight = 500;
}else if (slider2.value == 6) {
barHeight = 600;
}
self.orangeView.frame = CGRectMake(595, barX, 80, barHeight);
}
You should also move this to after your if else statement, otherwise it will only update with the previous value.
EDIT:
As rmaddy points out the if statement is a bit overkill in this instance. A switch may be more readable/efficient, but as your barHeight is simply the slider value multiplied by 100 it would be much easier to write:
- (void)valueAgeChanged:(UISlider*)slider2
{
barHeight = floorf(slider2.value) * 100;
self.orangeView.frame = CGRectMake(595, barX, 80, barHeight);
}

Scrabble drag technique

I had created an puzzle game which was like Scrabble.
Here is the layout:
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
What is my problem?
My problem was when I start touch from 1 and direction to 12, If touch and drag in slow then no problem but when drag in fast, I manage to 1, 6, 12 or 1, 7, 12 only. There is missing a number.
How to make sure the path numbers all be selected?
I am using touch began, touch moved and touch ended and check with coordinate to locate which number is being touched.
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesBegan:touches withEvent:event];
UITouch *touch = [touches anyObject];
CGPoint currentTouchLocation = [touch locationInView:self.numberview];
if(!ispause && [time.text intValue] > 0){
if(!isbegan && !isended){
for(int i = 1; i <= 16; i++)
{
UIView *imageview = [self.numberview viewWithTag:i];
if (CGRectContainsPoint(imageview.frame, currentTouchLocation))
{
isbegan = YES;
isreverse = NO;
if([[ischose objectAtIndex:i-1] boolValue] == 0)
{
currentposition = imageview.tag;
positionvalue += pow(i, 3);
currentanswer += [self converter:[NSString stringWithFormat:#"%#", [allimagenumbers substringWithRange:NSMakeRange(i-1, 1)]]];
[ischose replaceObjectAtIndex:i-1 withObject:[NSNumber numberWithBool:YES]];
[self changeimage:#"selected"];
}
break;
}
}
}
}
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
[super touchesMoved:touches withEvent:event];
UITouch *touch = [touches anyObject];
CGPoint currentTouchLocation = [touch locationInView:self.numberview];
float gapX = image1.frame.size.width / 8;
float gapY = image1.frame.size.height / 8;
if(isbegan && !isended)
{
if(currentTouchLocation.x >= 0 && currentTouchLocation.x <= self.numberview.frame.size.width && currentTouchLocation.y >= 0 && currentTouchLocation.y <= self.numberview.frame.size.height)
{
for(int i = 1; i <= 16; i++)
{
UIView *imageview = [self.numberview viewWithTag:i];
if (CGRectContainsPoint(imageview.frame, currentTouchLocation))
{
if((currentTouchLocation.x >= imageview.frame.origin.x + gapX && currentTouchLocation.x < imageview.frame.origin.x + imageview.frame.size.width - gapX) && (currentTouchLocation.y >= imageview.frame.origin.y + gapY && currentTouchLocation.y < imageview.frame.origin.y + imageview.frame.size.height - gapY ))
{
if([[ischose objectAtIndex:i-1] boolValue] == 0 && !isreverse)
{
currentposition = imageview.tag;
positionvalue += pow(i, 3);
currentanswer += [self converter:[NSString stringWithFormat:#"%#", [allimagenumbers substringWithRange:NSMakeRange(i-1, 1)]]];
[ischose replaceObjectAtIndex:i-1 withObject:[NSNumber numberWithBool:YES]];
[self changeimage:#"selected"];
}
else
{
if(currentposition != imageview.tag)
{
isreverse = YES;
}
else
{
isreverse = NO;
}
}
break;
}
}
}
}
else
{
isended = YES;
isoutofbound = YES;
if(isbegan && isoutofbound)
[self countinganswer];
}
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesEnded:touches withEvent:event];
if(!isoutofbound)
{
isended = YES;
[self countinganswer];
}
else
isoutofbound = NO;
}
-(void)changeimage:(NSString *)status{
if([status isEqualToString:#"default"])
{
for(int i = 1; i <=16;i++)
{
UIImageView *imageview = (UIImageView*)[self.numberview viewWithTag:i];
imageview.image = [UIImage imageNamed:[NSString stringWithFormat:#"stone%#", [allimagenumbers substringWithRange:NSMakeRange(i-1, 1)]]];
[image1 setUserInteractionEnabled:YES];
}
}
else if([status isEqualToString:#"correct"] || [status isEqualToString:#"selected"])
{
for(int i = 1; i<= ischose.count; i++)
{
if([[ischose objectAtIndex:i-1] boolValue] == 1)
{
UIImageView *imageview = (UIImageView*)[self.numberview viewWithTag:i];
imageview.image = [UIImage imageNamed:[NSString stringWithFormat:#"stone%#_correct", [allimagenumbers substringWithRange:NSMakeRange(i-1, 1)]]];
}
}
}
else if([status isEqualToString:#"wrong"] || [status isEqualToString:#"repeat"])
{
for(int i = 1; i<= ischose.count; i++)
{
if([[ischose objectAtIndex:i-1] boolValue] == 1)
{
UIImageView *imageview = (UIImageView*)[self.numberview viewWithTag:i];
imageview.image = [UIImage imageNamed:[NSString stringWithFormat:#"stone%#_wrong_repeat", [allimagenumbers substringWithRange:NSMakeRange(i-1, 1)]]];
}
}
}
}
Update:
Chatting with you, it appears that you have solved your problem (where a swipe over one of your UIImageView objects was not being detected). It looks like the solution was a unique issue (i.e. highly "localized" in Stack Overflow language) associated with your code to create reduced size "hit zones" that you constructed with your gap variables. It doesn't look like the solution was anything really associated with touchesMoved, iOS API, or iOS system performance. Regardless, I'm glad you solved the problem.
My original answer below was predicated on the original source code posted, which had the same logic repeated for each of the 16 UIImageView objects. I was just demonstrating how you can use a UIArray to significantly simplify that logic. I also use UIPanGestureRecognizer, which I think unifies the code, and with <UIKit/UIGestureRecognizerSubclass.h> you can cancel the gesture, in case the user's gesture went "out of bounds."
Original answer:
I'm assuming that you simply want to build an array of image numbers as the user drags their finger over the numbers. So the ARC code might look something like:
// NumberGameViewController.m
#import "NumberGameViewController.h"
#import <UIKit/UIGestureRecognizerSubclass.h>
#interface NumberGameViewController ()
{
NSArray *images;
NSMutableArray *results;
}
#end
#implementation NumberGameViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// if you build an array of your images, the logic to determine which image you're over is much easier
images = #[self.image1, self.image2, self.image3, self.image4, self.image5, self.image6, self.image7, self.image8, self.image9, self.image10, self.image11, self.image12, self.image13, self.image14, self.image15, self.image16];
// I know you used `touchesMoved` and the like, but I think gesture recognizers are a little easier
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:#selector(handlePan:)];
[self.numberview addGestureRecognizer:pan];
}
- (NSInteger)determineImageNumber:(CGPoint)point
{
for (NSInteger i = 0; i < [images count]; i++)
{
UIImageView *imageview = images[i];
// I'm just going to see if the user's finger was over the number in question.
// If you wanted more restrictive logic (e.g. 3/4ths of the frame), just adjust
// adjust the frame variable here.
CGRect frame = imageview.frame;
if (CGRectContainsPoint(frame, point))
return i;
}
return -1;
}
- (void)handlePan:(UIGestureRecognizer *)gesture
{
CGPoint location = [gesture locationInView:self.numberview];
NSInteger imageNumber = [self determineImageNumber:location];
static NSInteger lastImageNumber;
if (gesture.state == UIGestureRecognizerStateBegan)
{
results = [[NSMutableArray alloc] init];
if (imageNumber >= 0)
{
[results addObject:#(imageNumber)];
}
}
else if (gesture.state == UIGestureRecognizerStateChanged)
{
if (imageNumber >= 0)
{
if (imageNumber != lastImageNumber)
{
// If you want to do some visual adjustment of the image you're over, do it
// here.
// add the image to our array of results
[results addObject:#(imageNumber)];
// if you want to do some additional validation (e.g. do you have 16 points,
// has the user hit the same number twice, etc.), do that here
}
}
// by the way, let's check to see if we're still within the numberview subview, and if
// not, let's cancel the gesture
if (!CGRectContainsPoint(self.numberview.bounds, location))
{
gesture.state = UIGestureRecognizerStateCancelled;
return;
}
}
else if ((gesture.state == UIGestureRecognizerStateEnded) || (gesture.state == UIGestureRecognizerStateCancelled) || (gesture.state == UIGestureRecognizerStateFailed))
{
// At this point you'd do any final validation of the user's response, to see if they
// succeeded or not. I'm just displaying the results in the console
NSLog(#"%#", results);
}
if (imageNumber >= 0)
lastImageNumber = imageNumber;
}
#end
float gapX = image1.frame.size.width / 8;
float gapY = image1.frame.size.height / 8;
Here is the problem, there is a gap within all images so when fast drag it will be outer part of images

Touch Move Method issue in cocos2d for iphon4

I am developing one universal puzzle game, in which i have used separate image for iphone4 and for iphone3, iphone4 image is double in size of iphone3 image. My issue is for iphone4, touch area of image for iphone4 image is taking double size, suppose i have an image size for iphone4 is 20*40 and for iphone3 is 10*20, issue is touch area for iphone4 image is 40*80 i don't know how its happening i worked out in my code but i didnt get any solution of this issue, touching is working fine in iphone3, taking with in sprite rectangle.
can you one help me to solve this issue or tell me what i am forgetting to code for iphone4 touching so that its take touch with in sprite (image) rectangle
Thank in advance.
Here is my code:
`-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
touchLocation = [touch locationInView: [touch view]];
touchLocation = [[CCDirector sharedDirector] convertToGL:touchLocation];
touchLocation = [self convertTouchToNodeSpace:touch];
NSLog(#"touch location x = %f , y =%f",touchLocation.x,touchLocation.y);
CCSprite * sp= [CCSprite spriteWithFile:#"1.png"];
sp.position = ccp(touchLocation.x ,touchLocation.y);
// [self addChild:sp z:100];
CGRect myrec = [invisible[0] boundingBox];
if (CGRectContainsPoint(myrec, touchLocation) ) {
NSLog(#"oneeeeeeee");
}
[self selectSpriteForTouch:touchLocation];
// return TRUE;
}
- (void)panForTranslation:(CGPoint)translation {
if (selSprite) {
CGPoint newPos = ccpAdd(selSprite.position, translation);
selSprite.position = newPos;
}
}
- (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
Location = [touch locationInView: [touch view]];
Location = [[CCDirector sharedDirector] convertToGL:Location];
Location = [self convertTouchToNodeSpace:touch];
NSLog(#"touch moved location x = %f , y =%f",Location.x,Location.y);
//touchLocation = [self convertTouchToNodeSpace:touch];
CGPoint oldTouchLocation = [touch previousLocationInView:touch.view];
oldTouchLocation = [[CCDirector sharedDirector] convertToGL:oldTouchLocation];
oldTouchLocation = [self convertToNodeSpace:oldTouchLocation];
CGPoint translation = ccpSub(Location, oldTouchLocation);
if (CGRectContainsPoint(selspriterect,Location))
{
[self panForTranslation:translation];
}
if ([[UIScreen mainScreen] respondsToSelector:#selector(scale)])
{
NSLog(#"respond to selector");
CGFloat scale = [[UIScreen mainScreen] scale];
if (scale > 1.0)
{
NSLog(#"iphone 4s");
CGPoint mypoint = CGPointMake(80, 357);
CGPoint mypoint1 = CGPointMake(237, 360);
CGPoint mypoint2 = CGPointMake(79, 255);
CGPoint mypoint3 = CGPointMake(237, 247);
CGPoint mypoint4 = CGPointMake(78, 153);
CGPoint mypoint5 = CGPointMake(239, 140);
CCSprite *disablesprite=nil;
switch (selSprite.tag) {
case 0:
if (CGRectContainsPoint( [dest[0] boundingBox] , mypoint ) ) {
NSLog(#"oneeeeee collided");
dest[0].position = ccp(192,380);
// selSprite = disablesprite;
}
break;
case 1:
if (CGRectContainsPoint( [dest[1] boundingBox] , mypoint1 ) ) {
NSLog(#"two collided");
dest[1].position = ccp(258,379);
}
break;
case 2:
if (CGRectContainsPoint( [dest[2] boundingBox] , mypoint2 ) ) {
NSLog(#"three collided");
dest[2].position = ccp(173,281);
}
break;
case 3:
if (CGRectContainsPoint( [dest[3] boundingBox] , mypoint3 ) ) {
NSLog(#"four collided");
dest[3].position = ccp(258,281);
}
break;
case 4:
if (CGRectContainsPoint( [dest[4] boundingBox] , mypoint4 ) ) {
NSLog(#"five collided");
dest[4].position = ccp(166,181);
}
break;
case 5:
if (CGRectContainsPoint( [dest[5] boundingBox] , mypoint5 ) ) {
NSLog(#"six collided");
dest[5].position = ccp(258,176);
}
break;
default:
break;
}
}
else {
CGPoint mypoint = CGPointMake(106, 329);
CGPoint mypoint1 = CGPointMake(208, 329);
CGPoint mypoint2 = CGPointMake(97, 220);
CGPoint mypoint3 = CGPointMake(217, 220);
CGPoint mypoint4 = CGPointMake(92, 124);
CGPoint mypoint5 = CGPointMake(212, 124);
CCSprite *disablesprite=nil;
switch (selSprite.tag) {
case 0:
if (CGRectContainsPoint( [dest[0] boundingBox] , mypoint ) ) {
NSLog(#"oneeeeee collided");
dest[0].position = ccp(125,320);
// selSprite = disablesprite;
}
break;
case 1:
if (CGRectContainsPoint( [dest[1] boundingBox] , mypoint1 ) ) {
NSLog(#"two collided");
dest[1].position = ccp(200,312);
}
break;
case 2:
if (CGRectContainsPoint( [dest[2] boundingBox] , mypoint2 ) ) {
NSLog(#"three collided");
dest[2].position = ccp(117,209);
}
break;
case 3:
if (CGRectContainsPoint( [dest[3] boundingBox] , mypoint3 ) ) {
NSLog(#"four collided");
dest[3].position = ccp(200,208);
}
break;
case 4:
if (CGRectContainsPoint( [dest[4] boundingBox] , mypoint4 ) ) {
NSLog(#"five collided");
dest[4].position = ccp(113,127);
}
break;
case 5:
if (CGRectContainsPoint( [dest[5] boundingBox] , mypoint5 ) ) {
NSLog(#"six collided");
dest[5].position = ccp(207,126);
}
break;
default:
break;
}
}
}
}
-(void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
CGPoint mypoint = CGPointMake(106, 329);
CGPoint mypoint1 = CGPointMake(208, 329);
CGPoint mypoint2 = CGPointMake(97, 220);
CGPoint mypoint3 = CGPointMake(217, 220);
CGPoint mypoint4 = CGPointMake(92, 124);
CGPoint mypoint5 = CGPointMake(212, 124);
switch (selSprite.tag) {
case 0:
if (CGRectContainsPoint( [dest[0] boundingBox] , mypoint ) ) {
NSLog(#"oneeeeee collided");
if (corsprite == TRUE) {
correctplace++;
corsprite = FALSE;
}
}else {
selSprite.position = ccp(110,50);
}
break;
case 1:
if (CGRectContainsPoint( [dest[1] boundingBox] , mypoint1 ) ) {
NSLog(#"two collided");
if (corsprite2 == TRUE) {
correctplace++;
corsprite2 = FALSE;
}
}else {
selSprite.position = ccp(110, 65);
}
break;
case 2:
if (CGRectContainsPoint( [dest[2] boundingBox] , mypoint2 ) ) {
NSLog(#"three collided");
if (corsprite3 == TRUE) {
correctplace++;
corsprite3 = FALSE;
}
}else {
selSprite.position =ccp(130, 10);
}
break;
case 3:
if (CGRectContainsPoint( [dest[3] boundingBox] , mypoint3 ) ) {
NSLog(#"four collided");
if (corsprite4 == TRUE) {
correctplace++;
corsprite4 = FALSE;
}
}else {
selSprite.position = ccp(215, 10);
}
break;
case 4:
if (CGRectContainsPoint( [dest[4] boundingBox] , mypoint4 ) ) {
NSLog(#"five collided");
if (corsprite5 == TRUE) {
correctplace++;
corsprite5 = FALSE;
}
}else {
selSprite.position = ccp(220,70);
}
break;
case 5:
if (CGRectContainsPoint( [dest[5] boundingBox] , mypoint5 ) ) {
NSLog(#"six collided");
if (corsprite6 == TRUE) {
correctplace++;
corsprite6 = FALSE;
}
}else {
selSprite.position = ccp(220,70);
}
break;
default:
break;
}
`
Do this in your app delegate
[director enableRetinaDisplay:YES];
and make sure your images follows the convention.
e.g. for iPhone3 suppose you have image as image.png then your retina image must be image-hd.png
Well, everything should be in points e.g. i dont think you need the logic around the UIScreen scale property, and your logic for scale=1 should work identically on a retina and non-retina display.
Quick try : change scale > 1.0 to scale > 3.0 (the if should always branch to the else part, which you state 'works' on iPhone 3), just to see if this is correct. If it is, remove the logic around scale altogether and cleanup :) ... In my code, i have not had one legitimate case of figuring out whether the scale is 1.0 or otherwise.

enumeration values 'UIGestureRecognizerStatePossible', 'UIGestureRecognizerStateCancelled', and 'UIGestureRecognizerStateFailed' not handled in switch

When i using gesture functionality for flip up and down this is occurred kindly help to fix this error
- (void)doFlipForward:(UIGestureRecognizer *)aGestureRecognizer forOrientation:(UIInterfaceOrientation)anOrientation{
if(isAnimating)
return;
switch([aGestureRecognizer state])//There is occurred in this line
{
case UIGestureRecognizerStateBegan:
[CATransaction begin];
[CATransaction setDisableActions:YES];
[flipPage setHidden:NO];
[flipShadow setHidden:NO];
[CATransaction commit];
break;
case UIGestureRecognizerStateChanged:
{
CGFloat multiplier = 0.0f;
if(UIInterfaceOrientationIsPortrait(anOrientation))
{
multiplier = portraitMultiplierTable[(NSInteger)[aGestureRecognizer locationInView:self].x];
[thisPage setPortraitCurlAnimationPosition:multiplier];
[flipPage setPortraitCurlAnimationPosition:multiplier];
[flipShadow setPortraitCurlAnimationPosition:multiplier];
}
else
{
multiplier = landscapeMultiplierTable[(NSInteger)[aGestureRecognizer locationInView:self].x];
[thisPage setLandscapeCurlAnimationPosition:multiplier];
[flipPage setLandscapeCurlAnimationPosition:multiplier];
[flipShadow setLandscapeCurlAnimationPosition:multiplier];
}
}
break;
case UIGestureRecognizerStateEnded:
{
CGFloat transX = [(UIPanGestureRecognizer *)aGestureRecognizer translationInView:self].x;
CGFloat width = [self bounds].size.height * PAGE_RATIO;
if(width + transX < width/2)
{
[self animateOpen];
}
else
{
[self animateClose];
}
}
break;
}
}
You don't have a case for the listed values in the warning. Add the following to silence the warning:
default:
break;