Saturday, 17 August 2013

Display a UIView within a UITableViewCell pragmatically

Display a UIView within a UITableViewCell pragmatically

I am using the following code to instance a UIView from a XIB and then add
it to the selected UITableViewCell for displaying. When I run the code and
touch the cell, I can walk through the code and see that everything is
instanced correctly (nothing is nil) and yet the view is never displayed.
I have a UIView with a couple of buttons on it. In Interface Builder I set
the UIView to use a sub-class of UIView which at the moment does not have
any code in it, other than the boiler plate generated by Xcode. I'm hoping
someone can point out any obvious errors I've made in using this code to
get this to work.
Please note that at one point I had the UIView showing within the
UITalbeViewCell, but I had messed some stuff up during some refactoring
and ended up re-writing the code to handle this. When that happened, I
could no longer display the UIView within the cell.
@implementation HZRunwayViewController
{
EKEvent *currentEvent;
BOOL editingEvent;
HZEventDrawerView *eventDrawer;
}
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Check if we are touching an event
if (indexPath.section == 0 && [self.eventsForCurrentDay count]) {
// Grab the selected cell and make sure it's an event cell
UITableViewCell *cell = [self tableView:tableView
cellForRowAtIndexPath:indexPath];
if ([cell isKindOfClass:[HZEventTableViewCell class]]) {
// Setup our event cell and our action drawer for use.
HZEventTableViewCell *eventCell = (HZEventTableViewCell *)cell;
if (!eventDrawer) {
eventDrawer = (HZEventDrawerView *)[[NSBundle mainBundle]
loadNibNamed:@"HZEventDrawerView" owner:self
options:nil][0];
}
eventDrawer.bounds = eventCell.bounds;
NSLog(@"X:%f Y:%f Width: %f Height: %f",
eventDrawer.bounds.origin.x, eventDrawer.bounds.origin.y,
eventDrawer.bounds.size.width,
eventDrawer.bounds.size.height);
[eventCell.contentView addSubview:eventDrawer];
[eventCell bringSubviewToFront:eventDrawer];
eventDrawer.hidden = NO;
}
}
}

No comments:

Post a Comment