在'id'类型的对象上找不到属性'length'

时间:2012-08-13 12:57:03

标签: iphone

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"CustomCell";

    CustomCell *cell = (CustomCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
        for (id currentObject in topLevelObjects){
            if ([currentObject isKindOfClass:[UITableViewCell class]]){
                cell =  (CustomCell *) currentObject;
                break;
            }
        }
    }
    cell.nameLabel.text = [arrareasdata objectAtIndex:indexPath.row];
    cell.designLabel.text = [arrareasdata1 objectAtIndex:indexPath.row];

    if(([arrareasdata2 objectAtIndex:indexPath.row].length > 0)  
    {
        cell.emailLabel.text = [arrareasdata2 objectAtIndex:indexPath.row]
    }
    else
    {
        cell.emailLabel.text = @"";
    }

    cell.webLabel.text = [arrareasdata3 objectAtIndex:indexPath.row];


    return cell;
}

1 个答案:

答案 0 :(得分:1)

问题出在这里

if(([arrareasdata2 objectAtIndex:indexPath.row].length > 0)

你必须做的是从数组中获取对象并将其转换为适当的类型。例如,如果数组中的对象是NSString类型,那么请执行以下操作

NSString *value = (NSString*)[arrareasdata2 objectAtIndex:indexPath.row];

然后在你的if语句检查长度

if (value.length > 0)