设计单元时访问单元格内容

时间:2012-02-08 21:26:01

标签: xcode

在下面的代码中,我需要查看单元格的内容,以便在满足特定条件时添加特定图像。我如何/在哪里这样做?

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

    NSManagedObject *object = (NSManagedObject *)[entityArray objectAtIndex:indexPath.row];

    NSString *CellIdentifier = @"Cell";
    int indicator = UITableViewCellAccessoryNone;

    // Check to see if the object has child elements
    if(self.entityName == @"Disease")
    {
        self.title = @"Disease Groups";
        if([[object valueForKey:@"DiseaseToLab"] count] > 0)
        {
            indicator = UITableViewCellAccessoryDisclosureIndicator;
            CellIdentifier = @"CellWithDisclosure";
        }
    }
    else if(self.entityName == @"Lab")
    {       
        self.title = @"Labs";
        if([[object valueForKey:@"LabToTest"] count] > 0)
        {
            indicator = UITableViewCellAccessoryDisclosureIndicator;
            CellIdentifier = @"CellWithDisclosure";
        }

    }

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {

        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
        cell.textLabel.numberOfLines = 0;
        cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:15.0];
    }

    cell.accessoryType = indicator;
    cell.textLabel.text = [object valueForKey:@"Name"];

    // If we are looking at the test listing, indicate which tests are panel tests.
    if(self.entityName == @"Test")
    {

        cell.imageView.image = [UIImage imageNamed:@"PanelTestImage.png"];
    }

    return cell;
}

0 个答案:

没有答案