Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8941565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:20:05+00:00 2026-06-15T11:20:05+00:00

I have a gridview when i click on any image i send current index

  • 0

I have a gridview when i click on any image i send current index of that gridview so i can see that image. and I am loading images from doucment.
below is my viewDidload code.
but what my problem is. when i click any gridview item . let say its index is 4. and i set it here in currentpage=4. so when i open this page. it shows me 4th image. but my page controller current page is 4 but i can see my image which was at index 1.

- (void)viewDidLoad {
    [super viewDidLoad];

    pageControlBeingUsed = NO;
    UIImageView *subview;
    //NSArray *colors = [NSArray arrayWithObjects:[UIColor redColor], [UIColor greenColor], [UIColor orangeColor],[UIColor blueColor], nil];
    for (int i = 0; i < (NSInteger)totalImagesInGrid; i++) {
        CGRect frame;
        frame.origin.x = self.scrollView.frame.size.width * i;
        frame.origin.y = 0;
        frame.size = self.scrollView.frame.size;

        subview = [[UIImageView alloc] initWithFrame:frame];
        //subview.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:[tableDataArray objectAtIndex:i]]];
        NSString *name = [tableDataArray objectAtIndex:(NSUInteger)i];
        NSFileHandle* myFileHandle = [NSFileHandle fileHandleForReadingAtPath:name];
        UIImage* loadedImage = [UIImage imageWithData:[myFileHandle readDataToEndOfFile]];
        subview.image = loadedImage;
        [self.scrollView addSubview:subview];
        [subview release];
    }
    //float count = [totalImagesInGrid floatValue];
    self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * 13, self.scrollView.frame.size.height);
    self.pageControl.currentPage = (NSInteger)currentImage;
    NSLog(@"currentPage  %d",(NSInteger)currentImage);
    self.pageControl.numberOfPages = (NSInteger)totalImagesInGrid;
    NSLog(@"(NSInteger)totalImagesInGrid  %d",(NSInteger)totalImagesInGrid);
}

- (void)scrollViewDidScroll:(UIScrollView *)sender {
    if (!pageControlBeingUsed) {
        // Switch the indicator when more than 50% of the previous/next page is visible
        CGFloat pageWidth = self.scrollView.frame.size.width;
        int page = floor((self.scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
        self.pageControl.currentPage = (NSInteger)currentImage + page;
        NSLog(@"Page %d",page);
    }
    NSLog(@"scrollViewDidScroll");
}

- (IBAction)changePage {
// Update the scroll view to the appropriate page
CGRect frame;
frame.origin.x = self.scrollView.frame.size.width * self.pageControl.currentPage;
frame.origin.y = 0;
frame.size = self.scrollView.frame.size;
[self.scrollView scrollRectToVisible:frame animated:YES];


pageControlBeingUsed = YES;

}

this is my gridview and i m click on (1,1) image.

enter image description here

And this is my page control view. but thats not the image i have selected . this is (0,1) image but see at page control it is on index 2.

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T11:20:07+00:00Added an answer on June 15, 2026 at 11:20 am

    set page index with selectedIndex of gridview for example see bellow…

    - (void) gridView:(UIGridView *)grid didSelectRowAt:(int)rowIndex AndColumnAt:(int)colIndex{
        ///set Image with index of colIndex..
        int selectedIndex = (rowIndex*4)+colIndex;
        NSLog(@"\n Selected Image Index is %d",selectedIndex);
    }
    

    and in SecondView Class’s viewDidLoad: just call your secondView class method changePage at last of the method like bellow

    - (void)viewDidLoad {
        ////another your code
        [self changePage] 
    }
    

    i hope this help you..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a GridView with dynamically created image buttons that should fire command events
I have a GridView which you can click on a row and it should
I have a Gridview that displays a huge list of products. On Client click
I have editable grid view, If I click on edit in any row say
So I have a GridView in my ASPX page. When I click <asp:Button id=btnBindIt
I have a linkbutton in gridview and i want to click event on code
I have a gridview that needs to be exported to Excel. I have managed
I have a gridview that is within an updatepanel for a modal popup I
I have a Gridview that has a timestamp as one of the rows. When
I have a gridview that I load some ticket data into. Depending on the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.