GithubHelp home page GithubHelp logo

Visible cells nice to have about gmgridview HOT 8 OPEN

gmoledina avatar gmoledina commented on June 3, 2024
Visible cells nice to have

from gmgridview.

Comments (8)

tonyarnold avatar tonyarnold commented on June 3, 2024

Absolutely, I've run into this now so I'll see what I can do and push it back.

from gmgridview.

Maverick1st avatar Maverick1st commented on June 3, 2024

You can also get the visible cells like this:

 CGPoint contentOffset = ((UIScrollView*)[[gridView subviews]objectAtIndex:0]).contentOffset;
 for (GMGridViewCell *view in [[[gridView subviews]objectAtIndex:0] subviews])
 {
     ...
 }

But everytime you enter sorting mode the cells order seems to change in the subviews array. So this is not best solution. I'll try to make itemSubviews public and see if its better for my purpose.

Maybe I'll create a getCellsInRange Method or something like that, where you can also get a smaller amount of cells than the visible ones. Could be useful for some fancy animations. :)

btw. How do i make code tags in a comment?

from gmgridview.

Bejil avatar Bejil commented on June 3, 2024

I reached to get them like this :

Add @property (nonatomic) int index; to GMGridViewCell.h and @synthesize index; to his .m file:

Then in -(GMGridViewCell *)GMGridView:(GMGridView *)gridView cellForItemAtIndex:(NSInteger)index add cell.index=index; before return cell;.

All you have to do now is adding a public method to GMGridView:

-(NSArray *)indexPathsForVisibleRows;
-(NSArray *)indexPathsForVisibleRows{

    NSMutableArray *lc_array = [[NSMutableArray alloc] init];

    for(int i=0;i<[self.subviews count];i++){
        if(CGRectIntersectsRect(self.bounds, [[self.subviews objectAtIndex:i] frame]) && [[self.subviews objectAtIndex:i] isKindOfClass:[GMGridViewCell class]]){
            GMGridViewCell *subview = (GMGridViewCell *)[self.subviews objectAtIndex:i];
            [lc_array addObject:[NSIndexPath indexPathForRow:subview.index inSection:0]];
        }
    }
    return lc_array;
}

from gmgridview.

 avatar commented on June 3, 2024

The above solution "indexPathsForVisibleRows" for getting count of visible cells gives wrong results on orientation change. Unable to find the solution though.

from gmgridview.

Bejil avatar Bejil commented on June 3, 2024

Sorry I haven't noticed that cause I'm reloading data on rotation

from gmgridview.

 avatar commented on June 3, 2024

I too am reloading data on orientation change but the count comes wrong for me though.

from gmgridview.

Bejil avatar Bejil commented on June 3, 2024

I can't reproduce your problem. I'm using this method in order to use apple's lazy technique for cell' images. I always get the same association image/cell, rotation doesn't alter anything.

from gmgridview.

 avatar commented on June 3, 2024

My problem persists when GMGridView is scrolled to the end when the GMGridView is partially filled...
The scenario is as follows :
Datasource count = 44

Potrait mode = 2 columns * 7 rows = 14 cells
Landscape mode = 3 columns * 5 rows = 15 cells

Potrait mode
=> page 1 = count is 1 to 14. ==> 14 cells
=> page 2 = count is 15 to 28. ==> 14 cells
=> page 3 = count is 29 to 42. ==> 14 cells
=> page 4 = count is 43 to 44. ==> 2 cells

Landscape mode
=> page 1 = count is 1 to 15. ==> 15 cells
=> page 2 = count is 16 to 30. ==> 15 cells
=> page 3 = count is 31 to 44. ==> 14 cells

Now when I scroll to the 3rd page in landscape mode and then change the orientation, I reach the
to the 4th page but with count of 3rd page.

Also the [self.subViews count] gives me a different value each time the "indexPathsForVisibleRows" method is called. So I am considering "[[self itemSubviews] count]" as my counter for the for loop.

My grid view frame is ===> _gmGridView.frame=CGRectMake(10, 84, 1004, 565); for landscape

_gmGridView.frame=CGRectMake(10, 84, 748, 820); for potrait

Also the item cell size is as follows

  • (CGSize)GMGridView:(GMGridView *)gridView sizeForItemsInInterfaceOrientation:(UIInterfaceOrientation)orientation
    {
    return CGSizeMake(_gmGridView.frame.size.width/_numberOfColumn, _gmGridView.frame.size.height/_numberOfRowVisible);
    }

from gmgridview.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.