AlanQuatermain / AQGridView

A grid view for iPhone/iPad, designed to look similar to NSCollectionView.
http://quatermain.tumblr.com/
BSD 3-Clause "New" or "Revised" License
2.37k stars 446 forks source link

Displaying grid outside viewDidLoad possible? #153

Open TomWhitson opened 12 years ago

TomWhitson commented 12 years ago

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 commented 12 years ago

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/AlanQuatermain/AQGridView/issues/153.

TomWhitson commented 12 years ago

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 commented 12 years ago

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/AlanQuatermain/AQGridView/issues/153#issuecomment-8018950.

TomWhitson commented 12 years ago

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,

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?