gmoledina / GMGridView

A performant Grid-View for iOS (iPhone/iPad) that allows sorting of views with gestures (the user can move the items with his finger to sort them) and pinching/rotating/panning gestures allow the user to play with the view and toggle from the cellview to a fullsize display.
MIT License
2.3k stars 512 forks source link

ViewController as Subview does not work? #115

Open anujgakhar opened 12 years ago

anujgakhar commented 12 years ago

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

Anyone?

mwyman commented 12 years ago

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).

anujgakhar commented 12 years ago

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....