Image sorting bug in Scrollview - iPad application
===

We are building a catalog app that has 2 rows of sorted images with varying widths but same height. We draw the artwork on scrollview in sorted order (from A to Z) As per attached image.
 
We search using a alphabetically ordered bar on top that has letters (A to Z) If i touch on letter J the i want the artwork which starts from j  comes first. The code we are using is not working well. E.g. clicking on J takes us to A. Will greatly appreciate your help or advice.

Code is as follows:
 
                                               NSString *newStr = [currentArtworkTitle substringWithRange:NSMakeRange(0,1)];       
                if([newStr isEqualToString:self.searchString])
                    if (scrollViewTopRowWidth > scrollViewBottomRowWidth) {
                        xCordForSortedView = scrollViewTopRowWidth - c - imgForButton.size.width;//self.touchLengthCount;//50 ;// -10//c   scrollViewBottomRowWidth 
                    }
                    else {
                        xCordForSortedView = scrollViewBottomRowWidth - c - imgForButton.size.width;// self.touchLengthCount;//40;//scrollViewTopRowWidth
                    }
 
    // For shifting the screen
                                if(scrollViewTopRowWidth > scrollViewBottomRowWidth){
                                                                int tmpMargin = scrollViewTopRowWidth - xCordForSortedView;
                                                                if(tmpMargin < 1024)
                                                                                scrollView.contentSize = CGSizeMake(scrollViewTopRowWidth+1024, scrollView.bounds.size.height);
                                                }
                                                else{
                                                                int tmpMargin = scrollViewBottomRowWidth - xCordForSortedView;
                                                                if(tmpMargin < 1024)
                                                                                scrollView.contentSize = CGSizeMake(scrollViewBottomRowWidth+1024, scrollView.bounds.size.height);    
                                                }
                                                [scrollView scrollRectToVisible:CGRectMake(xCordForSortedView, 0, scrollView.frame.size.width, scrollView.frame.size.height) animated:YES];