错误:变量不是CFArray

时间:2012-03-21 14:48:01

标签: objective-c xcode4

我正在尝试按照此article创建自定义UITableViewCells。我为单元格中的三个字段添加了插座。我正在将数据存储在NSMutableArray中并将它们放在自定义单元格标签中。在调试时,我可以看到源数组元素中的数据,但这是在单元格标签中:“变量不是CFArray”。显然它不起作用......这是代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"--> cellForRowAtIndexPath");

    static NSString *CellIdentifier = @"siteTableCell";

    SiteListingsCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[SiteListingsCell alloc]
                initWithStyle:UITableViewCellStyleDefault 
                reuseIdentifier:CellIdentifier];
    }

    // Configure the cell...
    cell.staLabel.text = [self.staLabels objectAtIndex: [indexPath row]];
    cell.descLabel.text = [self.descLabels objectAtIndex:[indexPath row]];
    cell.dateLabel.text = [self.dateLabels objectAtIndex:[indexPath row]];

    return cell;
}

这是标签的定义:

@interface SiteListingsCell : UITableViewCell  {

}

@property (nonatomic, strong) IBOutlet UILabel *staLabel;
@property (nonatomic, strong) IBOutlet UILabel *descLabel;
@property (nonatomic, strong) IBOutlet UILabel *dateLabel;

@end

这是sArray的定义:

@interface sArray : NSObject  {  //  class (struct) to hold site information

}

@property (nonatomic, readwrite) NSString *sSiteID;
@property (nonatomic, readwrite) NSString *sInitialSTA;
@property (nonatomic, readwrite) NSString *sElev;
@property (nonatomic, readwrite) NSString *sJobDesc;
@property (nonatomic, readwrite) NSString *sJobDate;

@end

更新:当我想填充sArray并将值移动到自定义单元格标签时,将调用此代码:

- (void) displaySites {

    NSLog(@"displaySites");

    //  get list of sites and place them in sArray
    slSQLite *dbCode = [[slSQLite alloc] init];
    [dbCode getListOfSites];

    //  put site data into array for display
    NSLog(@"\n2-The array listOfSites contains %d items", dbCode.listOfSites.count);
 //   sArray *sa = [[sArray alloc] init];  // initialize sArray object

    for(int i = 0; i <dbCode.listOfSites.count; i++)  {
        sArray *sa = [dbCode.listOfSites objectAtIndex:i];  //  get the sArray out of listOfSites

        staLabels =  sa.sSiteID;
        descLabels = sa.sJobDesc;
        dateLabels = sa.sJobDate;
    }
    return;
}

如何解决这个问题呢?

1 个答案:

答案 0 :(得分:0)

尝试:

staLabels.text =  sa.sSiteID;

等...