Iphone 在ViewController内设置自定义UITableViewCell的UILabel.text

Iphone 在ViewController内设置自定义UITableViewCell的UILabel.text,iphone,ios,uitableview,Iphone,Ios,Uitableview,我有一个UITableView,我正在用interface builder中的自定义UITableViewCell填充它。我在访问这些自定义tableviewcells属性时遇到一些问题,希望得到一些帮助 在Interface Builder中,我将自定义tableviewcell的类设置为当前视图控制器(以便我可以将所有标签对象指定给Interface Builder中的正确标签),因此,我还在Interface Builder中将IBOutlet标签设置为正确的标签,但是当我尝试将NSStr

我有一个
UITableView
,我正在用interface builder中的自定义
UITableViewCell
填充它。我在访问这些自定义tableviewcells属性时遇到一些问题,希望得到一些帮助

在Interface Builder中,我将自定义tableviewcell的
类设置为当前视图控制器(以便我可以将所有标签对象指定给Interface Builder中的正确标签),因此,我还在Interface Builder中将
IBOutlet
标签设置为正确的标签,但是当我尝试将NSString从数组对象变量(类型为NSString)传递到UIlabel的文本时,会发生此错误

Property 'cellDescription' not found on object of type 'UITableViewCell *'
下面是我使用自定义tableviewcell设置tableview的代码,然后尝试用正确的文本填充单元格UILabels

- (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;
}

您必须将
UITableViewCell
键入到
AutomotiveSearchCell

我认为您在某个地方编写的代码很奇怪(autoSearchCell没有声明),但您必须执行以下操作

cell = (AutomotiveSerachCell* )autoSearchCell;
上述代码不起作用,应遵循以下代码


皈依

AutomotiveSearchCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

如果上述方法不起作用,请参考以下过程

  • 创建一个CustomCell类。

  • 制作一个自定义单元格xib。

  • 链接标签到CustomCell类。

  • 导入标题
    #导入“AutomotiveSearchCell.h”
    并复制和粘贴以下代码



  • hrmm。。它在结束括号中出现了
    预期表达式
    。。我需要在if声明之外打电话吗?我编辑了这篇文章。请退房。如果我看到了你的完整代码,我给出了清晰的答案。hrmm,似乎当我尝试使用
    cell
    /Users/imac/Documents/Iphone applications/ii//MSeriesViewController.m:154:27:使用未声明的标识符“cell”时,将其从UITableViewCell更改为AutomotiveSearchCell会给我这个错误。你是否导入了“AutomotiveSearchCell.h”?我的代码没有问题。请再检查一下<代码>UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:CellIdentifier]转换为
    AutomotiveSearchCell*单元格=[tableView dequeueReusableCellWithIdentifier:CellIdentifier]啊,AutomotiveSearchCell仅为.xib我已将currentViewController作为xibs类传递,因此我声明了当前类中的所有UIAbel,但我的AutomotiveSearchCell.xib可以从currentViewController中看到声明的UILabel
    
    AutomotiveSearchCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    - (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;
    }