Bazinga
Bazinga

Reputation: 2466

UIScrollView objectAtIndex

In my UIScrollView,I have 30 images in my array. I tried getting the objectAtIndex in my array. I want to be able to do is display an animation in a specific image when UIScrollView stop scrolling. So I tried this code below:

- (void) scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView{
    if([images objectAtIndex:0]){

        //Animation 1

    } else if([images objectAtIndex:1]){

        //Animation 2

    } else if{
...

}

But I cant make it do my animation. Is my condition possible or is there other way?

Upvotes: 0

Views: 397

Answers (2)

Bazinga
Bazinga

Reputation: 2466

Im applying NSNumber or NSString to my array. Like this:

for (int i=0; i<30;i++)
{

    //for NSString
    [arrayName addObject:[NSString stringWithFormat:@"%d", i]];

    //for  NSNumber
    [arrayName addObject:[NSNumber numberWithInt:i]];
}

Then in your scrollViewDidEndScrollingAnimation,implement either of this condition:

if ([[arrayName objectAtIndex:anIndex] intValue] == 1)

if ([arrayName objectAtIndex:anIndex] isEqualToString:@"1"])

Upvotes: 0

Joel
Joel

Reputation: 16134

Your code:

if([images objectAtIndex:0]) 

will evaluate if the object stored in the array images at index position 0 is nil or not. And presumably if the array is in bounds then it will return true. And if the array is out of bounds then that statement will cause a crash. So the result of your if statements will most likely be true or crash (unless you are storing nil pointers in the array for some reason).

What are you trying to evaluate? Are you trying to determine what image is showing when your scroll view stops scrolling?

Upvotes: 2

Related Questions