【发布时间】: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;}
动画非常慢,每次我不得不重新加载表格时都会变得最差。怎么了?
【问题讨论】:
-
通过分析器运行程序。
标签: objective-c ipad uitableview