I have to develop an iPad TV guide that looks like
What’s On TV.
I tried to do it using a UITableView with many row as the number of channels. In order to create a kind of grid, I added a subview for each row that contains all the programs (UIButton with different size). In order to scroll the view horizontally I added gesture recognizer and change the UIView (subview cell) position every time I swipe right or left.
That works, but the solution seems to me a bit messy and the animation is not so reactive. Do you have any idea (or example) for a better solution? What about html5?
Thanks
My code:
in ViewController.m
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
_chName = (UILabel *)[cell viewWithTag:4];
_chName.text=((Channel *)[_resultEPGChannel objectAtIndex:indexPath.row]).name;
_viewCell = (UIView *)[cell viewWithTag:2];
_viewCell.frame=CGRectMake(-_positionView, 0,2000, 77);
//add the view to the _viewCell (moving view) with the right program for each channel (row)
cp = [[ChannelProgram alloc] init] ;
cp.allProgram=[_resultEPGProgram objectAtIndex:indexPath.row];
[_viewCell addSubview:cp];
return cell;}
In ChannelProgram.m (subclass of UIView)
- (void)drawRect:(CGRect)rect{
int xPoint=2;
for (Program *singleProgram in allProgram) {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.backgroundColor=[UIColor lightGrayColor];
[button setTitle:singleProgram.title forState:UIControlStateNormal];
button.frame=CGRectMake(xPoint,0, singleProgram.lengthProgram,75);
[self addSubview:button];
xPoint = xPoint+singleProgram.lengthProgram+2;}
The animation it’s very slow, and become worst every time I had to reload the table. What’s wrong?
Event drawRect is own draw, every time redraw you will create new UIButton, so you may get a lot of UIButton far more than you need.
UIButton is a control, you can just add it to ChannelProgram at
- (id)initWithFrame:(CGRect)frameor- (id)initWithCoder:(NSCoder *)aDecoder, this will not cause any memory waste.