Last active
December 24, 2015 14:39
-
-
Save vikingosegundo/6814617 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(void)btnClicked:(UIButton*)button | |
{ | |
NSAssert([imageStr count] == [txtStr count], @"both arrays need to have the same number of items"); | |
idx += (button == self.nextButton) ? 1 : -1; // if nextButton increment, else decrement | |
idx = idx % [textStr count]; // modolo, will keep idx between 0 and count-1 | |
[stgImage1 setImage:[UIImage imageNamed: imageStr[idx]]]; | |
stgText1.text= [NSString stringWithFormat:@"%@", textStr[idx]]]; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(void)btnClicked:(UIButton*)btn{ | |
if (btn.tag==1) { | |
if (counter < [textStr count]) { | |
NSLog(@"%i", counter); | |
[stgImage1 setImage:[UIImage imageNamed:[imageStr objectAtIndex:counter]]]; | |
stgText1.text= [NSString stringWithFormat:@"%@", [textStr objectAtIndex:counter]]; | |
counter++; | |
} | |
if (counter >= [textStr count]) { | |
counter = 0; | |
} | |
} else { | |
if (counter>=0) { | |
counter--; | |
[stgImage1 setImage:[UIImage imageNamed:[imageStr objectAtIndex:counter]]]; | |
stgText1.text= [NSString stringWithFormat:@"%@", [textStr objectAtIndex:counter]]; | |
} | |
if(counter <= 0) { | |
counter = [textStr count]; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a answer to http://stackoverflow.com/questions/19087078/i-want-correct-format-of-this-code | |
First you should not use view's tag like that. Instead check the identity against a member/property. | |
Second I called your count variable idx — as it is a index variable. | |
As a pre-condition I check, if both arrays have the same size. Of course it would be much nicer to keep the information together: one NSDictionary per photo and caption. even better: a PhotoAlbumItem that stores both as properties. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment