1

私のプロジェクトでは、静的セルを含む tableView と動的セルを含む tableView があります。カスタマイズするために、セル (グループ化されたスタイル) にグラデーションの背景を取得することができました。

行の位置 (Top、Bottom、Middle、または single) に応じて cellForRowAtIndex... で背景ビューを設定すると、動的な TableViews で問題なく動作します。

ただし、静的なテーブルビュー セルに実装しようとすると、機能しません。cellForRowAtindex を実装しようとしましたが、クラッシュします。

誰かがアイデアを持っていますか?

更新: cellForRow のコード..

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];    

    UACellBackgroundView *bgw=[[UACellBackgroundView alloc]init];

    if (indexPath.row==0) {

        bgw.position = UACellBackgroundViewPositionTop;
        cell.backgroundView=bgw;

    }else if (indexPath.row==2){

        bgw.position = UACellBackgroundViewPositionBottom;
        cell.backgroundView=bgw;

    }else {
        bgw.position = UACellBackgroundViewPositionMiddle;
        cell.backgroundView=bgw;
    }

  //  cell.backgroundView=bgw;


    return cell;
}

ちなみに、ここから取得した背景ビュー: http://code.coneybeare.net/how-to-make-custom-drawn-gradient-backgrounds とここ: http://pessoal.org/blog/2009 /02/25/customizing-the-background-border-colors-of-a-uitableview/

誰かが興味を持っている場合

4

2 に答える 2

1

UITablViewCell を割り当てているようには見えません。セルを割り当てる必要があります。

例えば:

- (UITableViewCell *)tableView:(UITableView *)tableView 
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        // alloc the UITableViewCell
        // remeber if you are not using ARC you need to autorelease this cell
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    cell.textLabel.text = @"Cell Name";
    cell.detailTextLabel.text = @"Cell Detail";

    return cell;
}

次のステートメントを追加します。

if (cell == nil) {
    // alloc the UITableViewCell
    // remeber if you are not using ARC you need to autorelease this cell
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
于 2012-05-19T19:56:19.567 に答える
1

静的テーブルを持つ UITableViewController サブクラスがある場合は、セルをデキューしようとしないでください。
代わりsuperに、セルを要求する必要があります。スーパークラスはストーリーボードからセルを取得し、それを構成できます。

このようなもの:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [super tableView:tableView cellForRowAtIndexPath:indexPath];

    UIView *selectedBackgroundView = [[UIView alloc] init];
    cell.selectedBackgroundView = selectedBackgroundView;
    cell.selectedBackgroundView.backgroundColor = [UIColor mb_tableViewSelectionColor];
    return cell;
}

他のすべての属性にも機能します。

于 2013-09-03T10:14:14.603 に答える