iPad 电视指南应用程序
Posted
技术标签:
【中文标题】iPad 电视指南应用程序【英文标题】:iPad TV guide app 【发布时间】:2011-11-15 10:22:01 【问题描述】:我必须开发一个 iPad 电视指南,看起来像 What's On TV.
我尝试使用具有多行作为通道数的 UITableView 来做到这一点。为了创建一种网格,我为包含所有程序的每一行添加了一个子视图(具有不同大小的 UIButton)。为了水平滚动视图,我添加了手势识别器并在每次向右或向左滑动时更改 UIView(子视图单元格)位置。
这行得通,但在我看来,解决方案有点混乱,而且动画不是那么被动。您对更好的解决方案有任何想法(或示例)吗? html5呢?
谢谢
我的代码:
在 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;
在 ChannelProgram.m(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;
动画非常慢,每次我不得不重新加载表格时都会变得最差。怎么了?
【问题讨论】:
通过分析器运行程序。 【参考方案1】:事件drawRect是自己的draw,每次重绘都会创建一个新的UIButton,所以你得到的UIButton可能远远超出你的需要。
UIButton是一个控件,你可以把它添加到- (id)initWithFrame:(CGRect)frame
或- (id)initWithCoder:(NSCoder *)aDecoder
的ChannelProgram,这样不会造成内存浪费。
【讨论】:
感谢您的回答.. 我使用了 initWithFrame 并且效果很好!以上是关于iPad 电视指南应用程序的主要内容,如果未能解决你的问题,请参考以下文章