2011-11-15 86 views
-4

我必須開發一個iPad電視指南,看起來像 What's On TViPad電視指南應用程序

我嘗試使用一個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;} 

這是非常緩慢的動畫,每次我不得不重新加載表格時變得最差。怎麼了?

+0

通過分析器運行程序。 – Edwin

回答

0

事件drawRect是自己繪製的,每次重畫你將創建新的UIButton,所以你可能會得到很多UIButton遠遠超過你的需要。

UIButton是一個控件,您可以將它添加到ChannelProgram - (id)initWithFrame:(CGRect)frame- (id)initWithCoder:(NSCoder *)aDecoder,這不會造成任何內存浪費。

+0

感謝您的回答..我用了initWithFrame,就像一個魅力! – user1047132