Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Displaying grid outside viewDidLoad possible? #153

Open
TomWhitson opened this issue Aug 24, 2012 · 4 comments
Open

Displaying grid outside viewDidLoad possible? #153

TomWhitson opened this issue Aug 24, 2012 · 4 comments
Labels

Comments

@TomWhitson
Copy link

In my viewDidLoad I create a gridview set size, colors etc and assign delegate/datasource to self but at present there is no data to display. This is pulled from the web at a later date, thus when I get my callback I would like to populate the grid outside viewDidLoad simply by adding data to the appropriate array and calling reloadData. If I try this it seems that the grid is not displaying until I interact with it or switch tabs and back.

So what I saw is that the various datasoure methods are called, and this causes various AQGridView calls to be made (I put logs in layoutsubviews and the like), but my screen stays blank for the time being. If I then change tab and back again I don't see any logs from within AQGridView but my grid appears as I expect.

Has anyone implamented the loading of a grid outside of viewDidLoad, if so any tips? Or should this work "out of the box" and I am missing something....what could iOS be calling when switching tabs back again? I have tried variuos calls such as setNeedsLayout/Display but nothing seems to work.

Any feedback appreciated...

@evadne
Copy link
Collaborator

evadne commented Aug 24, 2012

I am afraid to suggest that your understanding of iOS view controller
lifecycle may be erroneous. This issue has perhaps very little to do with
AQGridView.

But let’s go back to app design and figure out what it is supposed to do.

You can very possibly keep the data and not erase or destroy it even when
the view is going away.

Sample code or project code welcome.

On 2012-08-24, at 3:38, TomWhitson notifications@github.com wrote:

In my viewDidLoad I create a gridview set size, colors etc and assign
delegate/datasource to self but at present there is no data to display.
This is pulled from the web at a later date, thus when I get my callback I
would like to populate the grid outside viewDidLoad simply by adding data
to the appropriate array and calling reloadData. If I try this it seems
that the grid is not displaying until I interact with it or switch tabs and
back.

So what I saw is that the various datasoure methods are called, and this
causes various AQGridView calls to be made (I put logs in layoutsubviews
and the like), but my screen stays blank for the time being. If I then
change tab and back again I don't see any logs from within AQGridView but
my grid appears as I expect.

Has anyone implamented the loading of a grid outside of viewDidLoad, if so
any tips? Or should this work "out of the box" and I am missing
something....what could iOS be calling when switching tabs back again? I
have tried variuos calls such as setNeedsLayout/Display but nothing seems
to work.

Any feedback appreciated...


Reply to this email directly or view it on
GitHubhttps://github.com//issues/153.

@TomWhitson
Copy link
Author

Hi, it could well be that I misunderstand...new to iOS and trying to learn.

So my psuedo-code is,

viewDidLoad{
self.gridView = [[AQGridView alloc] initWithFrame:CGRectMake(0, 0, 768, 955)];
self.gridView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
self.gridView.autoresizesSubviews = YES;
self.gridView.delegate = self;
self.gridView.dataSource = self;
[self.view addSubview:gridView];
[self.gridView reloadData];

    //make async call to we service
    [aWebService asyncCall];

}

aSyncCallBack{
//we recieved our data so lets show it
self.tableData = aSyncCallBackData;
[seld.gridView reloadData];
}

So this is what i am trying to achieve, async call in viewDidLoad and then reloadData in the async delegate callback. So it seems ok to me...but perhaps i am missing something??

As i said the grid does not show up to begin with when we call reloadData but if we click a cell or change tabs back and forth then it shows up.

Thanks in advance for the ideas.

@evadne
Copy link
Collaborator

evadne commented Aug 25, 2012

One pattern that might work is to have something that loads data into a
backing store. On view load, trigger data loading if necessary. Otherwise
populate the view with data. When data loads, refresh the view anyway.

On 2012-08-24, at 18:32, TomWhitson notifications@github.com wrote:

Hi, it could well be that I misunderstand...new to iOS and trying to learn.

So my psuedo-code is,

viewDidLoad{
self.gridView = [[AQGridView alloc] initWithFrame:CGRectMake(0, 0, 768,
955)];
self.gridView.autoresizingMask =
UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
self.gridView.autoresizesSubviews = YES;
self.gridView.delegate = self;
self.gridView.dataSource = self;
[self.view addSubview:gridView];
[self.gridView reloadData];

//make async call to we service
[aWebService asyncCall];

}

aSyncCallBack{
//we recieved our data so lets show it
self.tableData = aSyncCallBackData;
[seld.gridView reloadData];
}

So this is what i am trying to achieve, async call in viewDidLoad and then
reloadData in the async delegate callback. So it seems ok to me...but
perhaps i am missing something??

As i said the grid does not show up to begin with when we call reloadData
but if we click a cell or change tabs back and forth then it shows up.

Thanks in advance for the ideas.


Reply to this email directly or view it on
GitHubhttps://github.com//issues/153#issuecomment-8018950.

@TomWhitson
Copy link
Author

Hmm so I tried something like that, start the data load, load some dummy data, then reload when the new data arrives. This provides some even more strange behaviour though as far as I can see.

When I load the dummy data it is fine, I load 8 cells with images and title, all displays as it should.
When i reload the data, with more like 33 items, again with images and titles then the images don't update unless I change tabs in my app (or click a cell). Then even when the new images do load only the original 8 cells reload their images.

Seems to me like an issue with reuse of cells? But as far as I know I did everything expected when creating the cell,

  • (AQGridViewCell *) gridView: (AQGridView *) aGridView cellForItemAtIndex: (NSUInteger) index
    {
    NSString * FilledCellIdentifier = [NSString stringWithFormat:@"%@-%i", @"dsfds", index];//@"FilledCellIdentifier";
    AQGridViewCell * cell = nil;
    ImageDemoFilledCell * filledCell = (ImageDemoFilledCell *)[aGridView dequeueReusableCellWithIdentifier: FilledCellIdentifier];
    if ( filledCell == nil )
    {
    filledCell = [[ImageDemoFilledCell alloc] initWithFrame: CGRectMake(0.0, 0.0, 200.0, 200.0)
    reuseIdentifier: FilledCellIdentifier];
    filledCell.selectionStyle = AQGridViewCellSeparatorStyleEmptySpace;
    filledCell.backgroundColor = [UIColor blackColor];
    filledCell.backgroundView = nil;
    }

    NSURL *imageURL;
    NSData *imageData;
    imageURL = [NSURL URLWithString:[m_playList objectAtIndex:index]];
    imageData = [NSData dataWithContentsOfURL:imageURL];

    [filledCell setImage:[UIImage imageWithData:imageData]];
    filledCell.title = @"ASDAD";
    cell = filledCell;
    return ( cell );
    }

I allocate the image outside the if(filledCell == nil) so that the image is changed even on reuse, so it seems to me that is ok.

Is there any setting I should be looking into which changes the ideas around reuse/relayout?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants