0

私はインターフェイスビルダーUITableViewでカスタムを入力しているものを持っています。UITableViewCellこれらのカスタムtableviewcellsプロパティへのアクセスに問題があり、助けを期待しています。

Interface Builderでは、カスタムtableviewcellclassを現在のViewコントローラーに設定しています(これにより、すべてのラベルオブジェクトをInterface Builderで正しいラベルに割り当てることができます)。したがって、InterfaceBuilderでラベルIBOutletを正しいラベルに設定しました。 NSStringを配列オブジェクト変数(NSStringタイプ)からUIlabelのテキストに渡そうとするとエラーが発生します。

Property 'cellDescription' not found on object of type 'UITableViewCell *'

以下は、カスタムtableviewcellを使用してテーブルビューを設定し、セルのUILabelに正しいテキストを入力するために使用したコードです。

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

    if (indexPath.section == 0) {      
        // Set cell height
        [self tableView:tableView heightForRowAtIndexPath:indexPath];

        // Configure the cell using custom cell
        [[NSBundle mainBundle] loadNibNamed:@"AutomotiveSearchCell" owner:self options:nil];

        cell = autoSearchCell;

        //call dataArrayOfObject that has all of the values you have to apply to the custom tableviewcell
        SearchResultItem* myObj = (SearchResultItem*)[dataArrayOfObjects objectAtIndex:indexPath.row];

        cell.cellDescription.text = myObj.seriesDescription; // This is where I am receiving the error

        NSLog(@"%@", myObj.seriesDescription); // This logs the correct value

        //Disclosure Indicator
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }

    return cell;
}
4

1 に答える 1

2

UITableViewCellタイプする必要がありますCastingToAutomotiveSearchCell

どこか奇妙なコード(autoSearchCellの宣言はありません)だと思いますが、次のことを行う必要があります。

cell = (AutomotiveSerachCell* )autoSearchCell;

上記のコードは機能しません。次のコードが必要です。


UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

に変換

AutomotiveSearchCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

それでも問題が解決しない場合は、次のプロセスを参照してください。

  1. CustomCellクラスを作成します。 ここに画像の説明を入力してください

  2. CustomCellxibを作成します。 ここに画像の説明を入力してください ここに画像の説明を入力してください ここに画像の説明を入力してください

  3. CustomCellクラスにリンクされたラベル。 ここに画像の説明を入力してください

  4. ヘッダー#import "AutomotiveSearchCell.h"をインポートし、次のコードをコピーして貼り付けます。


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    AutomotiveSearchCell *cell = nil;

    if(!cell)
    {
        UINib *nib = [UINib nibWithNibName:@"AutomotiveSearchCell" bundle:nil];
        NSArray *arr = [nib instantiateWithOwner:nil options:nil];
        cell = [arr objectAtIndex:0];
        cell.cellDescription.text = @"Test~!~!~!";
    }

    // Configure the cell...

    return cell;
}

ここに画像の説明を入力してください

于 2012-08-15T02:41:57.030 に答える