GMGridView icon indicating copy to clipboard operation
GMGridView copied to clipboard

ViewController as Subview does not work?

Open anujgakhar opened this issue 13 years ago • 3 comments

I've got a Grid View and it works fine if I keep adding Labels/Images etc to the cel's contentView. e.g. this would work fine [cell.contentView addSubview:myhumbnail];

But this does not work.....nothing gets displayed

ItemDetailsController *details = [[ItemDetailsController alloc] init]; [cell.contentView addSubview:artworkDetails.view];

Any ideas why this would not work ?

anujgakhar avatar May 30 '12 08:05 anujgakhar

Anyone?

anujgakhar avatar Jun 02 '12 18:06 anujgakhar

Is the ItemDetailsController's view getting created correctly (is it valid when you attempt to add it as a subview)?

Also, does your case really call for a view controller? While UIViewController does sound all MVC-ish, it's not really meant for small views going into a grid...

Also, in general you should avoid directly adding a UIViewController's view as a subview of another view controller. It often doesn't play nice, without a lot of bookkeeping code. And I believe Apple has said it may be completely disallowed in iOS 5+ (unless you go through the correct bookkeeping process).

mwyman avatar Jun 15 '12 08:06 mwyman

Yes, since I posted this question, I realised I did not really need a View Controller. I have since switched to a UIView and all seems to be playing along well.

if (!cell) { cell = [[GMGridViewCell alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)]; ItemDetailView *cellView = [[ItemDetailView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
cellView.backgroundColor = [UIColor whiteColor]; }

ItemDetail *detail = [self.details objectAtIndex:index];
ItemDetailView *detailView = (ItemDetailView*)cell.contentView;
[ItemDetailView setDetail:detail];

This seems to work nicely and I assume the cells are being re-used too by doing so....

anujgakhar avatar Jun 15 '12 08:06 anujgakhar